楼主: Tigflanker
1979 3

[问答] 求助一个infile + input问题 [推广有奖]

  • 8关注
  • 18粉丝

副教授

49%

还不是VIP/贵宾

-

威望
0
论坛币
2321 个
通用积分
9.8528
学术水平
179 点
热心指数
194 点
信用等级
167 点
经验
27443 点
帖子
622
精华
0
在线时间
851 小时
注册时间
2011-3-27
最后登录
2023-5-14

80论坛币
  1. data attrib;
  2.   infile datalines dlm = '|';
  3.   input pgm $ title $char500. footnote $char2000. point $ @@;
  4. datalines4;
  5. t_1|
  6. title1 "title1 for &pgm.";|
  7. footnote1 "footnote1 for t_1";
  8. footnote2 "footnote2 for t_1";|
  9. 6.3|

  10. t_2|
  11. title1 "title1 for &pgm.";
  12. title2 "title2 for &pgm.";|
  13. footnote1 "footnote1 for t_2";
  14. footnote2 "footnote2 for t_2";
  15. footnote3 "footnote3 for t_2";|
  16. 5.2
  17. ;;;;
  18. run;
复制代码
求助input问题,输入有点free style,不过变量都是按照|这个符号来分隔的;
最终还是被input击败了,救助,谢谢:)

最佳答案

pobel 查看完整内容

data attrib; length str $4000; infile datalines dlm = '|' _infile_=tmp ; do while (count(str,"|")
关键词:infile Input file NFI put title

本帖被以下文库推荐

Bye SAS.
若有缘,能重聚。
沙发
pobel 在职认证  发表于 2014-11-18 11:37:57 |只看作者 |坛友微信交流群
data attrib;
  length str  $4000;
  infile datalines dlm = '|' _infile_=tmp ;
  do while (count(str,"|")<3);
    input ;
        str=cats(str,tmp);
  end;

  pgm=scan(str,1,"|");
  title=scan(str,2,"|");
  footnote=scan(str,3,"|");
  input point;

  drop str;
datalines4;
t_1|
title1 "title1 for &pgm.";|
footnote1 "footnote1 for t_1";
footnote2 "footnote2 for t_1";|
6.3|
t_2|
title1 "title1 for &pgm.";
title2 "title2 for &pgm.";|
footnote1 "footnote1 for t_2";
footnote2 "footnote2 for t_2";
footnote3 "footnote3 for t_2";|
5.2
;;;;
run;
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Tigflanker + 5 + 3 + 3 + 3 非常感谢,理解中。。。

总评分: 论坛币 + 5  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

使用道具

藤椅
sas9.4 发表于 2014-11-18 17:37:31 |只看作者 |坛友微信交流群
竖线是个累赘,try this


data attrib (where= (point>0) drop=temp);
length temp footnote title $500 pgm $8;
retain footnote ''  title '' pgm '';
infile datalines ;
input temp  &  $500. ;

if find(temp,'title')>0 then title= strip(title)|| tranwrd(temp,'|','');
else if  find(temp,'footnote')>0 then footnote= strip(footnote)|| tranwrd(temp,'|','');
else if anyalpha(tranwrd(temp,'|',''))=0 then point= input(tranwrd(temp,'|',''),best.) ;
else pgm = tranwrd(temp,'|','');
output;
  if point>0  then call missing(title,footnote, pgm);
datalines4;
t_1|
title1 "title1 for &pgm.";|
footnote1 "footnote1 for t_1";
footnote2 "footnote2 for t_1";|
6.3|
t_2|
title1 "title1 for &pgm.";
title2 "title2 for &pgm.";|
footnote1 "footnote1 for t_2";
footnote2 "footnote2 for t_2";
footnote3 "footnote3 for t_2";|
5.2
;;;;

run;
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Tigflanker + 5 + 3 + 3 + 3 非常感谢!!

总评分: 论坛币 + 5  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

使用道具

板凳
bobguy 发表于 2014-11-19 11:28:08 |只看作者 |坛友微信交流群
You can do it sa simple as below.   

data _null_;
      infile 'c:\temp\attrib.txt';
          file 'c:\temp\attrib.mod' ls =32767;
      input;
          if length(_infile_)>1 then put _infile_ @;  
    run;

        data attrib;
        length pgm $10 title $200 footnote $400 point 8;
        infile 'c:\temp\attrib.mod' delimiter='|' ls =32767;
        input pgm title  footnote  point @@;
        run;

        proc print;run;
已有 1 人评分论坛币 学术水平 热心指数 信用等级 收起 理由
Tigflanker + 5 + 3 + 3 + 3 Thank you Bob, first time to see MOD fil

总评分: 论坛币 + 5  学术水平 + 3  热心指数 + 3  信用等级 + 3   查看全部评分

使用道具

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注cda
拉您进交流群

京ICP备16021002-2号 京B2-20170662号 京公网安备 11010802022788号 论坛法律顾问:王进律师 知识产权保护声明   免责及隐私声明

GMT+8, 2024-4-28 12:22