BookmarkSubscribeRSS Feed
Subbarao
Fluorite | Level 6

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.

5 REPLIES 5
Loko
Barite | Level 11

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

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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

Kurt_Bremser
Super User

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.

Subbarao
Fluorite | Level 6

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;

SASKiwi
PROC Star

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.

sas-innovate-2024.png

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.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1122 views
  • 3 likes
  • 5 in conversation