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?
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.