Hello,
How does this program execute?
data test;
set sashelp.class;
do until(eof);
set sashelp.class end=eof;
output;
end;
run;
Look at the log after running this and see if you get any enlightenment:
data test; set sashelp.class; put 'Before loop'; do until(eof); put 'At begin of loop' +1 name=; set sashelp.class end=eof; put 'In loop after set' +1 name=; output; put; end; run;
Try it, and read the log. If puzzled, come back here.
Form a hypothesis test it, report the results, and why you think those results occurred. Then you'll get plenty of responses.
@mkeintz 1. "do until (eof); ....... " runs just in one loop as it is DOW-LOOP setting.
2. _n_ increments by 1 and implicit loop terminates.
data test;
put _all_;
set sashelp.class;
put _all_;
run;
data test;
put _all_;
do until(eof);
set sashelp.class end=eof;
output;
put _all_;
end;
run;
Look at the log after running this and see if you get any enlightenment:
data test; set sashelp.class; put 'Before loop'; do until(eof); put 'At begin of loop' +1 name=; set sashelp.class end=eof; put 'In loop after set' +1 name=; output; put; end; run;
Building on ballardw's advice, try
data test;
set sashelp.class(rename=(Name=FirstName));
put 'Before loop';
do until(eof);
put 'At begin of loop' +1 FirstName=;
set sashelp.class end=eof;
put 'In loop after set' +1 FirstName= +1 name=;
output;
put;
end;
run;
A nice variation to further illustrate the behaviour of set statements and loops:
data test;
set sashelp.class;
do while (not eof);
set sashelp.class end=eof;
output;
end;
run;
The question you may want to ask instead is When does this program stop?
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.