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