data one;
do i = 9 to 11;
nextfile = "C:\sasuser\month"!!compress(put(i,2.))!!".txt";
infile temp filevar=nextfile;
input num;
output;
end;
/*stop;*/
run;
if i comment the stop keyword, program going to infinite loop, what makes programe to go infinite loop, can somebody please explain?
In those files, i have data num.
My assumption is after run, it is again going to Data step and executing whole code again and again. Is it true?? If at all this is the reason, why the below code is not going infinite loop?
data one;
a=1;
run;
Can somebody please explain? Thank you very much.
Hello,
The reason is that it reads infinitely from the file nextfile. you shall tell SAS to stop reading from each
nextfile when reaching its end. PLease check example 5 here:
http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000146932.htm
Rather than having a do loop, why not use wildcards on the infile?
What actually happens is this:
- start data step iteration
- start do loop
- set infile and read 1 (first) record
- output
- iterate to next in the do loop
- when do loop has finished, go to start of data step
since you start reading every infile again in each data step iteration, you never encounter an end-of-file condition, so the data step never stops.
I suggest you read every infile with a do until (eof); and infile ..... end=eof; inside the do loop.
Thank you that make sense. But, when i apply same logic, why below programme stops execution after run statement, what makes end=eof makes enable?
DATA ONE;
A=1;
RUN;
In your example you are not reading any data in so SAS knows it does not need to loop reading in data row by row. So it will just execute A=1 once then 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.