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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 799 views
  • 1 like
  • 4 in conversation