BookmarkSubscribeRSS Feed
abhishekbhatia02
Calcite | Level 5

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

1 REPLY 1
gergely_batho
SAS Employee

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 623 views
  • 3 likes
  • 2 in conversation