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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 1 reply
  • 911 views
  • 3 likes
  • 2 in conversation