Help using Base SAS procedures

Logic of this o/p

Reply
N/A
Posts: 1

Logic of this o/p

Hi, can you explain how this o/p is obtained when the following program is executed

data abc;

input a $ b;

datalines;

A 20

B 40

C 60

D 80

;

run;

data xyz;

do i = 1 to 3;

set abc;

X + 1;

output;

end;

run;

proc print data=xyz; run;

Please also throw some light at what point Set statement is read

SAS Employee
Posts: 340

Re: Logic of this o/p

Hi,

Execute this data step, which sheds some light of the execution:

data xyz;

do i = 1 to 3;

     putlog 'BEFORE' _ALL_;

     set abc;

     X + 1;

     output;

     putlog 'AFTER ' _ALL_;

end;

run;

First the inner loop is executed 3 times, and 3 rows from abc dataset are read into the PDV, and than output. This is only the first data step cycle (_N_=1). (Remember: data step always constructs a loop if you use a set,merge,infile,update,modify statement.)

Then comes the second cycle of the data step (_N_=2).

The inner loop starts 2 times: First it is executed completely, but in the second iteration there comes the set statement. And this is the moment, when the data step finishes (exits, stops), because there are no more observations in abc dataset.

Ask a Question
Discussion stats
  • 1 reply
  • 170 views
  • 3 likes
  • 2 in conversation