After researching, still don't quite understand why var X in Brother Three is only 2 & 4 and data 5,Karl is gone as well, new to SAS, please help!thanks
One way to look at this:
The values in the first data set are "replaced" by the values in the second data set (if they exist).
So, all the VarX in the first data set have been replaced by all the VarX in the second data set.
All the VarY have made it to the end, as there are no VarY in the second data set.
Similarly, the VarZ appear in the final data set, as there is nothing to replace them.
One way to look at this:
The values in the first data set are "replaced" by the values in the second data set (if they exist).
So, all the VarX in the first data set have been replaced by all the VarX in the second data set.
All the VarY have made it to the end, as there are no VarY in the second data set.
Similarly, the VarZ appear in the final data set, as there is nothing to replace them.
This program does not interleave anything, since it is missing this statement:
by VarX;
Try adding it and examine the results.
Then turn the two SET statements into a single statement (the normal way to interleave) and examine the results:
data brothers.three;
set brothers.one brothers.two;
by varX;
run;
Two SET statements means 2 parallel streams of data. When any SET reaches beyond end of its data step, the data step stops. so the result is no longer than the shorter incoming data set.
MERGE (without an associated BY statement) on the other hand, wlll not stop the data step until the longer incoming is exhausted. So
data want;
merge brothers.three brothers.two;
run;
would yield three observations.
If you use SET one two; by varx;, then you will get interleaved datasets, because it's a single multi-component stream.
Actually, the program written by pchen002 could be described as one-to-one reading:
"One-to-one reading combines observations from two or more SAS data sets by creating observations that contain all of the variables from each contributing data set. Observations are combined based on their relative position in each data set, that is, the first observation in one data set with the first in the other, and so on. The DATA step stops after it has read the last observation from the smallest data set."
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.