BookmarkSubscribeRSS Feed
rajeshalwayswel
Pyrite | Level 9

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..

5 REPLIES 5
WarrenKuhfeld
Rhodochrosite | Level 12
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.

SuryaKiran
Meteorite | Level 14

 

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
Tom
Super User Tom
Super User

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.

mkeintz
PROC Star

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.

--------------------------
The hash OUTPUT method will overwrite a SAS data set, but not append. That can be costly. Consider voting for Add a HASH object method which would append a hash object to an existing SAS data set

Would enabling PROC SORT to simultaneously output multiple datasets be useful? Then vote for
Allow PROC SORT to output multiple datasets

--------------------------
Ksharp
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 5 replies
  • 1123 views
  • 4 likes
  • 6 in conversation