Hi, I have one question on infinite loop. There are two programs, which are shown below.
Why does program A work fine but program B generates infinite loop? thanks.
Program A:
filename qtr1 ('c:\sasuser\month1.dat''c:\sasuser\month2.dat'
'c:\sasuser\month3.dat');
data work.firstqtr;
infile qtr1;
input Flight $ Origin $ Dest $
Date : date9. RevCargo : comma15.;
run;
Program B:
data work.quarter;
do Month = 9, 10, 11;
nextfile="c:\sasuser\month"
!!compress(put(Month,2.)!!".dat",' ');
do until (lastobs);
infile temp filevar=nextfile end=lastobs;
input Flight $ Origin $ Dest $ Date : date9.
RevCargo : comma15.;
output;
end;
end;
run;
!!compress(put(Month,2.)!!".dat",' ');
Don't you mean
||put(Month,2.)||".dat";
You used exclamation marks. Why do you take the compress function?
Is this a test?
SAS normally stops a data step when it reads past the end of the input data set or text file.
Run this little example to see what I mean.
data _null_;
put 'BEFORE INPUT' _n_= ;
input ;
put 'AFTER INPUT' _n_ = ;
cards;
1
2
3
;
In your second data step the conditions on your DO loops prevent it from reading past the end of the data. So on iteration 1 it does DO MONTH=9,10,11 and then on iteration 2 it does it again, ad infinitum. Add a STOP statement before the RUN statement.
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.