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

Hi I have a got two data sets and I have shown them below. I'm trying to merge them by duplicating one of the columns "A " in dataset 1 depending on the number of entries of column "B" in dataset 2 for the same ID.

 

Dataset 1                              

IDA
1234xyz
1245abc
1245xya
4567abd
4567xyz
4567abc

 

Dataset 2

IDB
1234100-1
1234112-4
1245116-5
456745-8
456796-7
4567152-7

 

After merging I would like the result to be as follows.

IDAB
1234xyz100-1
1234xyz112-4
1245abc116-5
1245xya116-5
4567abd45-8
4567abd96-7
4567abd152-7
4567xyz45-8
4567xyz96-7
4567xyz152-7
4567abc45-8
4567abc96-7
4567abc152-7

 

I have tried the norming merging and interleaving but it doesn't work.

Does it require if the else and do looping to get this result ?

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Astounding
PROC Star

That looks like it's just a typographical error.  Try:

 

on A.ID = B.ID

 

Other than that, the logic looks sound.

View solution in original post

5 REPLIES 5
LinusH
Tourmaline | Level 20
No, just a simple SQL join.
Data never sleeps
SASKiwi
PROC Star

EDIT - Code corrected - your joining rule has duplicate key values in both input datasets so this is best done with SQL:

 

proc sql;
  create table want as 
  select A.ID
         ,A.A
         ,B.B
   from Dataset1 as A
   inner join Dataset2 as B
   on A.ID = B.ID
   ;
quit;

 

Ritu_Gowlikar
Calcite | Level 5

The above code gave me a cartisian product of the two data sets. Not the result which I  was looking for.Thanks anyways.

Astounding
PROC Star

That looks like it's just a typographical error.  Try:

 

on A.ID = B.ID

 

Other than that, the logic looks sound.

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