BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
KafeelBasha
Quartz | Level 8

How interleaving is different from Merging?

 

Help me with an example.

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Patrick
Opal | Level 21

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.

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26l...

 

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. 

 

View solution in original post

3 REPLIES 3
FreelanceReinh
Jade | Level 19

Please see these examples from SAS documentation:

Patrick
Opal | Level 21

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.

http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#n1tgk0uanvisvon1r26l...

 

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. 

 

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3 replies
  • 767 views
  • 1 like
  • 4 in conversation