BookmarkSubscribeRSS Feed
Hedegaard
Calcite | Level 5

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.

1 REPLY 1
Haikuo
Onyx | Level 15

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

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 910 views
  • 0 likes
  • 2 in conversation