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

I've the datasets as follows.

 

data have1;
    input Segment $ Expenses RC;
    datalines;
7183_AS1 1234.50 453.97 
7183_AS2 654.78 325.98 
;
run;

data have2;
    input Segment $ Country $ Currency $;
    datalines;
7183_AS1 USA Dollar
7183_AS1 USA Dollar
7183_AS1 USA Dollar
7183_AS2 USA Dollar
7183_AS2 USA Dollar
;
run;

Now I want to get the results as below. I tried with right join and inner join but it didn't worked either.

 

Segment	Country	Currency Expenses RC
7183_AS1  USA	Dollar	1234.50	453.97
7183_AS1  USA	Dollar	1234.50	453.97
7183_AS1  USA	Dollar	1234.50	453.97
7183_AS2  USA	Dollar	654.78	325.98
7183_AS2  USA	Dollar	654.78	325.98

In summary I want all records from 'have2' plus the matching values from 'Expenses' and 'RC' variables from 'have1'. Any guidance?

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20

If SQL, 



data have1;
    input Segment $ Expenses RC;
    datalines;
7183_AS1 1234.50 453.97 
7183_AS2 654.78 325.98 
;
run;

data have2;
    input Segment $ Country $ Currency $;
    datalines;
7183_AS1 USA Dollar
7183_AS1 USA Dollar
7183_AS1 USA Dollar
7183_AS2 USA Dollar
7183_AS2 USA Dollar
;
run;

proc sql;
 create table want as
 select a.*,expenses,rc
 from have2 a left join have1 b
 on a.segment=b.segment;
quit;

View solution in original post

4 REPLIES 4
PeterClemmensen
Tourmaline | Level 20

Like this?

 

data want;
   merge have2 have1;
   by Segment;
run;
David_Billa
Rhodochrosite | Level 12
Right, How to do this with join?
novinosrin
Tourmaline | Level 20

If SQL, 



data have1;
    input Segment $ Expenses RC;
    datalines;
7183_AS1 1234.50 453.97 
7183_AS2 654.78 325.98 
;
run;

data have2;
    input Segment $ Country $ Currency $;
    datalines;
7183_AS1 USA Dollar
7183_AS1 USA Dollar
7183_AS1 USA Dollar
7183_AS2 USA Dollar
7183_AS2 USA Dollar
;
run;

proc sql;
 create table want as
 select a.*,expenses,rc
 from have2 a left join have1 b
 on a.segment=b.segment;
quit;
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1031 views
  • 0 likes
  • 4 in conversation