what makes this prog to go infinite loop

Reply
Contributor
Posts: 39

what makes this prog to go infinite loop

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.

Super Contributor
Posts: 308

Re: what makes this prog to go infinite loop

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

Super User
Super User
Posts: 7,970

Re: what makes this prog to go infinite loop

Rather than having a do loop, why not use wildcards on the infile?

Super User
Posts: 7,809

Re: what makes this prog to go infinite loop

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.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Contributor
Posts: 39

Re: what makes this prog to go infinite loop

Posted in reply to KurtBremser

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;

Super User
Posts: 3,255

Re: what makes this prog to go infinite loop

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.

Ask a Question
Discussion stats
  • 5 replies
  • 388 views
  • 3 likes
  • 5 in conversation