BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

I wonder what second set statement do? 

data mydata (Keep=PlanID plandate);
set enrollment1 enrollment2; /*This set statement, appends two data sets: enrollment1 and enrollment2 */
set abc.grpTemp;/* what does this second set do?*/
Run;

Regards,

blueblue

Blue Blue
3 REPLIES 3
ballardw
Super User

Suggestion: Make three small data sets. The first two should be structured similar (same number of variables with same names and types) and the third one contain completely different data. Make the third data set with more records than the first two combined.

See what happens when you use them in similar code. Hint: do not use the KEEP option. See what happens without it first.

Quentin
Super User

The SET statement reads a record from a dataset.

each time

set enrollment1 enrollment2;

executes, it will read a record from enrollment1 or enrollment2 (after it has finished reading records from enrollment1)

 

Each time

set abc.grpTemp;

executes it will read a record from abc.grpTemp.

 

This is an unusual coding pattern.  Your final result will depend in part on the number of records in each dataset.

 

Understanding this step will give you a good understanding of the DATA step.  I would play around with a small example of this data, and add PUT statements, or play around in the DATA step debugger.

 

data mydata (Keep=PlanID plandate);
set enrollment1 enrollment2; /*This set statement, appends two data sets: enrollment1 and enrollment2 */
put _ALL_;
set abc.grpTemp;/* what does this second set do?*/
put _ALL_;
Run;

That said, I wouldn't trust a step like this.  If abc.grpTemp does not have the expected number of records, you could end up with some surprising results.  And also there is a possibility of variable collisions.

 

BASUG is hosting free webinars Next up: Mike Raithel presenting on validating data files on Wednesday July 17. Register now at the Boston Area SAS Users Group event page: https://www.basug.org/events.
mkeintz
PROC Star

The first SET statement, as you realize, reads data from enrollment1 (N=n1)  and appends data from enrollment2 (N=n2).

 

For each of those n1+n2 cases, the second SET reads an observation form abc.grptemp (N=n3).

 

EXCEPT: the data step will stop when either of the two SETs reach end of data.  MYDATA will have MIN(n3,n1+n2) observations.

 

The are other issues as well.  For example, any variable that is both in abc.grptemp and the appended sequence enrollment1+enrollment2 will end up with the value taken from the second SET.   So if you reversed the order of the SET statements, you'd end up with the same number of observations, but different values in such overlapping variables.

 

 

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

--------------------------

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 3 replies
  • 407 views
  • 3 likes
  • 4 in conversation