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?
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.