Desktop productivity for business analysts and programmers

Merge process with multiple variables

Accepted Solution Solved
Reply
Super Contributor
Super Contributor
Posts: 318
Accepted Solution

Merge process with multiple variables

Hello, i need help to merge below table

have1

var1                       var2                 var3_a

1234567891        15721572       au

1234567891        26702670        io

have2

var1                        var2                  var3_b

1234567891        15721572        au

1234567891         26702670       io

1234567891         11301130       io

merge by var1 var2

want

1234567891        15721572       au

1234567891        26702670       io

1234567891        11301130       io

Thanks............


Accepted Solutions
Solution
‎11-17-2014 10:30 PM
Respected Advisor
Posts: 3,124

Re: Merge process with multiple variables

Given both tables are sorted by var1-var3,

data want;

set have1 have2;

by var1 var2 var3;

run;

Haikuo

View solution in original post


All Replies
Trusted Advisor
Posts: 1,203

Re: Merge process with multiple variables

proc sql;

select a.* from have2 a

left join have1 b

on a.var1=b.var1

and a.var2=b.var2;

quit;

Respected Advisor
Posts: 3,124

Re: Merge process with multiple variables

May I ask what is the difference between "have2" and "want"?

Super Contributor
Super Contributor
Posts: 318

Re: Merge process with multiple variables

sorry Hai.Kuo - so in some cases i have below situation;

var1                       var2                 var3_a

1234567891        15721572       au

1234567891        26702670       zz

have2

var1                        var2                  var3_b

1234567891        15721572        au

1234567891         26702670       io

1234567891         11301130       do

merge by var1 var2

want

var1                       var2                 var3_a

1234567891        15721572       au

1234567891        26702670       zz

1234567891         26702670       io

1234567891         11301130       do




thanks.......

Solution
‎11-17-2014 10:30 PM
Respected Advisor
Posts: 3,124

Re: Merge process with multiple variables

Given both tables are sorted by var1-var3,

data want;

set have1 have2;

by var1 var2 var3;

run;

Haikuo

Super User
Super User
Posts: 6,338

Re: Merge process with multiple variables

Does not look like you want to MERGE the tables as that would imply that you wanted to combine records from different tables based on matching key variables.  Looks more like you want to UNION the two tables.

proc sql ;

create table want as

  select var1,var2,var3_a as var3 from have1

  union

  select var1,var2,var3_b as var3 from have2

;

Super Contributor
Super Contributor
Posts: 318

Re: Merge process with multiple variables

Thanks Hai.kuo and Tom...Now i have two options Smiley Happy Smiley Happy Smiley Happy

☑ This topic is SOLVED.

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

Discussion stats
  • 6 replies
  • 413 views
  • 3 likes
  • 4 in conversation