Help using Base SAS procedures

SQL Match Few to Many (SAS 9.2)

Accepted Solution Solved
Reply
Contributor
Posts: 45
Accepted Solution

SQL Match Few to Many (SAS 9.2)

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,


Accepted Solutions
Solution
‎10-19-2015 07:49 AM
Super User
Posts: 11,343

Re: SQL Match Few to Many (SAS 9.2)

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


All Replies
Super User
Posts: 5,431

Re: SQL Match Few to Many (SAS 9.2)

Join...?

Data never sleeps
Solution
‎10-19-2015 07:49 AM
Super User
Posts: 11,343

Re: SQL Match Few to Many (SAS 9.2)

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;
Respected Advisor
Posts: 4,926

Re: SQL Match Few to Many (SAS 9.2)

Or go natural:

 

Proc sql;
   create table want as
   select *
   from dataset1 natural left join dataset2;
quit;
PG
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 282 views
  • 0 likes
  • 4 in conversation