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
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.
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.
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.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.