Hello,
Suppose I have the following small piece of code:
data row1col1;
a = 12;
output;
run;
data _null_;
put nobs=;
*stop;
set row1col1 nobs=nobs;
run;
Notice that the stop statement in the data _null_ step has been commented out. Then the code puts nobs to the log twice, but I don't understand why it doesn't just put it once, nor why it puts a non-zero value, since the "put" statement is above the "set" statement.
If I include the stop statement, it puts nobs just once.
There are numerous paper talking about this, briefly speaking, data step will loop a 'half' loop until reach 'set' statement after the end of the data set has been reached. Considering the following scenarios:
data row1col1;
a = 12;
output;
run;
/*1. 0 obs: just a half loop*/
data empty;
set row1col1(obs=0);
run;
data _null_;
put nobs=;
*stop;
set empty nobs=nobs;
run;
/*2. with 'put' after 'set': one and half loop while not reaching 'put'*/
data _null_;
set row1col1 nobs=nobs;
put nobs=;
run;
Of course, with 'stop', it stops in the middle the loop before even one loop can be finished.
HTH,
Haikuo
Update: here is a paper by the famous Ian whitlock: http://www2.sas.com/proceedings/sugi22/ADVTUTOR/PAPER34.PDF
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.