DATA Step, Macro, Functions and more

join two dataset by using two variables

Accepted Solution Solved
Reply
Contributor
Posts: 20
Accepted Solution

join two dataset by using two variables

Hi, dear all,

 

I want to merge two datasets by using proc sql.

 

dataset A                                                     dataset B                       

id        code       price                        id        ved       price   

1          a           15                            1          af          15

1          f            13                            2          cd          13

2          b            11                           3          ed          8

2          a            13                            4         ff          13

3          c            10                            5         gs           15

4          d           10                           

4          b           13     

 

I want to merge those two datasets on two variables id and price.

The expected result is 

 

merged table

id      price    code   ved

1          15        a       af

2          13        a       cd

4           13       b       ff

 

I want to keep all the rest information in both datasets.

 

Thank you so much 

 

Best,

 

Yanting


Accepted Solutions
Solution
Monday
Contributor
Posts: 37

Re: join two dataset by using two variables

Prof sql noprint;
Create table want as
select *
From datasetA as x right join datasetB as y
On x.id=y.id and x.price=y.price
Quit;

Note make sure price and ID should be same format either numeric or characters
PS

View solution in original post


All Replies
Solution
Monday
Contributor
Posts: 37

Re: join two dataset by using two variables

Prof sql noprint;
Create table want as
select *
From datasetA as x right join datasetB as y
On x.id=y.id and x.price=y.price
Quit;

Note make sure price and ID should be same format either numeric or characters
PS
Contributor
Posts: 37

Re: join two dataset by using two variables

Posted in reply to shahparth260

Thank you !!!

PS
☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 75 views
  • 0 likes
  • 2 in conversation