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?
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
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.