全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 SAS专版
1510 2
2010-03-09
If we try to read all observations from input files.  Let's assume the following two programs were designed for the same purpose.
Example 1
data newfilename;
  ...
  do until (lastobs);
    infile temp filevar=nextfile end=lastobs;
    input <variable list>;
    output;
  end;
stop;
run;

Example 2
data newfilename;
...
  infile temp filevar=nextfile end=lastobs;
    do while (lastobs=0);
        input <variable list>;
        output;
    end;
run;



I am not sure about Example 2.  It seems the last observation will not be read in Example 2 because lastobs=1 for the last obs so the input loop won't work.  Am I right here?

Thanks!
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

全部回复
2010-3-13 23:55:09
dolphinfish 发表于 2010-3-9 20:14
If we try to read all observations from input files.  Let's assume the following two programs were designed for the same purpose.
Example 1
data newfilename;
  ...
  do until (lastobs);
    infile temp filevar=nextfile end=lastobs;
    input ;
    output;
  end;
stop;
run;

Example 2
data newfilename;
...
  infile temp filevar=nextfile end=lastobs;
    do while (lastobs=0);
        input ;
        output;
    end;
run;



I am not sure about Example 2.  It seems the last observation will not be read in Example 2 because lastobs=1 for the last obs so the input loop won't work.  Am I right here?

Thanks!
Here is an example to illustrate how the loop work and the value is populated.
data t1;
infile 'c:\downloads\b.txt' end=lastobs;
    do while (lastobs=0);
      n+1;
       put 'before ' n=  lastobs= ;
        input x;
        output;
        put 'after ' n= lastobs=/;
    end;
   stop;
    cards;
1
2
3
4
5
;

465  data t1;
466  infile 'c:\downloads\b.txt' end=lastobs;
467      do while (lastobs=0);
468        n+1;
469         put 'before ' n=  lastobs= ;
470          input x;
471          output;
472          put 'after ' n= lastobs=/;
473      end;
474     stop;
475      cards;

NOTE: The infile 'c:\downloads\b.txt' is:
      Filename=c:\downloads\b.txt,
      RECFM=V,LRECL=256,File Size (bytes)=13,
      Last Modified=13Mar2010:10:26:23,
      Create Time=13Mar2010:10:26:23

before n=1 lastobs=0
after n=1 lastobs=0

before n=2 lastobs=0
after n=2 lastobs=0

before n=3 lastobs=0
after n=3 lastobs=0

before n=4 lastobs=0
after n=4 lastobs=0

before n=5 lastobs=0
after n=5 lastobs=1
NOTE: 5 records were read from the infile 'c:\downloads\b.txt'.
      The minimum record length was 1.
      The maximum record length was 1.
NOTE: The data set WORK.T1 has 5 observations and 2 variables.
NOTE: DATA statement used (Total process time):
      real time           0.01 seconds
      cpu time            0.00 seconds
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

2010-3-20 22:28:07
才看到这个回信。明白了!谢谢
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群