DATA Step, Macro, Functions and more

SET statement and OUTPUT and PDV

Reply
Frequent Contributor
Posts: 84

SET statement and OUTPUT and PDV

[ Edited ]

data a;
set sashelp.class sashelp.class;output;
set sashelp.class;output;
run;

 

NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: There were 1 observations read from the data set SASHELP.CLASS.
NOTE: There were 19 observations read from the data set SASHELP.CLASS.
NOTE: The data set WORK.A has 39 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.03 seconds
cpu time 0.03 seconds

 

 

Can someone explain why we getting 1 for observation for 2nd dataset I guess we get total of 38 observations I just confuse in it..

SAS Super FREQ
Posts: 496

Re: SET statement and OUTPUT and PDV

Posted in reply to rajeshalwayswel
data a;
set sashelp.class(in=a) sashelp.class(in=b);aa=a; bb=b; output;
set sashelp.class(in=c); cc=c; output;
run;
proc print; run;

When you have doubts about what SAS is doing, ask SAS to explain. So I set binary flags so that you can see from where each observation originates. Near the end of processing, William is read from the first mention of the data set.  Then it is read from the last.  Then on the next pass, Alfred is read from the second data set, then SAS hits end of file on the last data set.  So only one obs is read from the second mention.

Super Contributor
Posts: 478

Re: SET statement and OUTPUT and PDV

[ Edited ]
Posted in reply to rajeshalwayswel

 

Hi,

 

Read this document under the heading Combining SAS Data Sets

http://support.sas.com/documentation/cdl/en/lrdict/64316/HTML/default/viewer.htm#a000173782.htm#a000...

 

 

"If the data sets contain common variables, the values that are read in from the last data set replace the values that were read in from earlier ones. "

 

 

Thanks,
Suryakiran
Super User
Super User
Posts: 7,860

Re: SET statement and OUTPUT and PDV

[ Edited ]
Posted in reply to rajeshalwayswel

The notes seem pretty clear. You read in 39 observations and wrote out 39 observations.

 

For the first 19 times through the data step loop you read and write twice and so generate 38 output records.

But on the 20th time through the loop the first SET/OUTPUT pair runs and writes the 39th output record, but the data step stops when it reads past the end of the data in the second SET statement.

Trusted Advisor
Posts: 1,294

Re: SET statement and OUTPUT and PDV

The first SET statement has an incoming stream of up to 38 obs. The second has 19.   So there are 19 iterations of the data step in which both SETs read a record.

 

On the 20th iteration, the first SET is successful (but at that point is just starting its 2nd data set file.   But the 20th iteration also exceeds the limit of the 2nd SET, thereby terminating the data step. So the first SET reads 19 +1, and the second  reads 19.

Super User
Posts: 10,623

Re: SET statement and OUTPUT and PDV

Posted in reply to rajeshalwayswel

Good question.

I just want say.

 

NOTE: There were 19 observations read from the data set SASHELP.CLASS.

data a;
set sashelp.class sashelp.class;output;
set sashelp.class;output;
run;

 


NOTE: There were 1 observations read from the data set SASHELP.CLASS.

data a;
set sashelp.class sashelp.class;output;
set sashelp.class;output;
run;

 


NOTE: There were 19 observations read from the data set SASHELP.CLASS.

data a;
set sashelp.class sashelp.class;output;
set sashelp.class;output;
run;

Ask a Question
Discussion stats
  • 5 replies
  • 217 views
  • 4 likes
  • 6 in conversation