DATA Step, Macro, Functions and more

Putting to the log twice, but expecting only once

Reply
Contributor
Posts: 24

Putting to the log twice, but expecting only once

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.

Respected Advisor
Posts: 3,124

Re: Putting to the log twice, but expecting only 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

Ask a Question
Discussion stats
  • 1 reply
  • 139 views
  • 0 likes
  • 2 in conversation