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

Hello and thank you for taking the time to look at this for me.

I have two dataset that I am working with in SAS 9.2.  I need to match by a common id (parent_id) then I need to pull the data from one data set and copy it to the other data set that has the matching parent_id.  This data set also has multiple of the same parent_id for some cases, but the child_ids are unique for each and every parent.  

 

Data Have 1

 

parent_id   child_id   child_info

1                     a           unique_1

2                     b           unique_2

2                     c           unique_3

2                     d           unique_4

3                     e           unique_5

4                     f           unique_6

4                     g           unique_7

 

Data 2 Have

parent_id     parent_info        Parent_info2

1                       aa                       aaa

2                       bb                       bbb

3                       cc                       ccc

4                       dd                       ddd

 

Data Want

Parent_id    Child_id    child_info     parent_info  parent_info2

1                     a           unique_1             aa               aaa

2                     b           unique_2             bb               bbb

2                     c           unique_3             bb               bbb

2                     d           unique_4             bb               bbb

3                     e           unique_5             cc               ccc

4                     f            unique_6             dd               ddd

4                     g           unique_7             dd               ddd

 

 

Guidance on this topic is greatly appreciated.

Thank you,
Jeff S. O,

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Basic Left Join

Proc sql;
   create table want as
   select a.*, b.parent_info, b.parent_info2
   from dataset1 as a left join dataset2 as b 
           on a.parent_id = b.parent_id;
quit;

View solution in original post

3 REPLIES 3
LinusH
Tourmaline | Level 20

Join...?

Data never sleeps
ballardw
Super User

Basic Left Join

Proc sql;
   create table want as
   select a.*, b.parent_info, b.parent_info2
   from dataset1 as a left join dataset2 as b 
           on a.parent_id = b.parent_id;
quit;
PGStats
Opal | Level 21

Or go natural:

 

Proc sql;
   create table want as
   select *
   from dataset1 natural left join dataset2;
quit;
PG

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!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 813 views
  • 0 likes
  • 4 in conversation