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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 1 reply
  • 658 views
  • 0 likes
  • 2 in conversation