楼主: dolphinfish
1533 2

求教:Loop counts [推广有奖]

  • 0关注
  • 0粉丝

已卖:703份资源

讲师

24%

还不是VIP/贵宾

-

威望
0
论坛币
2768 个
通用积分
0.6353
学术水平
1 点
热心指数
4 点
信用等级
1 点
经验
13027 点
帖子
150
精华
0
在线时间
679 小时
注册时间
2009-8-26
最后登录
2021-5-29

楼主
dolphinfish 发表于 2010-3-9 20:14:10 |AI写论文

+2 论坛币
k人 参与回答

经管之家送您一份

应届毕业生专属福利!

求职就业群
赵安豆老师微信:zhaoandou666

经管之家联合CDA

送您一个全额奖学金名额~ !

感谢您参与论坛问题回答

经管之家送您两个论坛币!

+2 论坛币
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!
二维码

扫码加我 拉你入群

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

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

关键词:counts Count loop NTS observations 求教 loop counts

回帖推荐

bobguy 发表于2楼  查看完整内容

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 ...

本帖被以下文库推荐

沙发
bobguy 发表于 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
已有 1 人评分经验 论坛币 收起 理由
bakoll + 3 + 3 精彩帖子

总评分: 经验 + 3  论坛币 + 3   查看全部评分

藤椅
dolphinfish 发表于 2010-3-20 22:28:07
才看到这个回信。明白了!谢谢

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

本版微信群
加好友,备注cda
拉您进交流群
GMT+8, 2025-12-9 05:53