How interleaving is different from Merging?
Help me with an example.
The documentation provides very detailed explanations with examples. I believe this is more than any of us can give you as an answer in this forum.
I suggest you read through the docu. Come back if there is something still not clear to you after reading the docu and ask your question(s) refering to what's in the docu.
Please see these examples from SAS documentation:
The documentation provides very detailed explanations with examples. I believe this is more than any of us can give you as an answer in this forum.
I suggest you read through the docu. Come back if there is something still not clear to you after reading the docu and ask your question(s) refering to what's in the docu.
Well:
Data1
ID RESULT
1 10
2 5
Data2
ID RESULT
1 16
3 17
Interleaving:
data want; set data1 data2; by ID; run;
Would give:
ID RESULT
1 10
1 16
2 5
3 17
It works a bit like looping over the distinct by variables, so loop 1 is for ID=1, take all records from data1 where ID=1, then all records from data2 where ID=1, next loop do ID=2 etc.
Merging:
data want; merge data1 data2 (rename=(result=result2)); by ID: run;
Would give:
ID RESULT RESULT2
1 10 16
2 5
3 17
In the above, as the two datasets have a variable the same, the second has to be renamed. What happens is the data from the second data is merged onto the first, so where data1.id=1 and data2.id=1 then that row comes out, then if data1.id=2 and data2.id=2, and so on. As ID=2 does not exist in the second data then that variable is set to missing, same for 3 as that variable does not appear in data1. The ID variable is always present (although missing is also possible) as it is the merge key variable.
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.