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

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............

1 ACCEPTED SOLUTION

Accepted Solutions
Haikuo
Onyx | Level 15

Given both tables are sorted by var1-var3,

data want;

set have1 have2;

by var1 var2 var3;

run;

Haikuo

View solution in original post

6 REPLIES 6
stat_sas
Ammonite | Level 13

proc sql;

select a.* from have2 a

left join have1 b

on a.var1=b.var1

and a.var2=b.var2;

quit;

Haikuo
Onyx | Level 15

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

woo
Barite | Level 11 woo
Barite | Level 11

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.......

Haikuo
Onyx | Level 15

Given both tables are sorted by var1-var3,

data want;

set have1 have2;

by var1 var2 var3;

run;

Haikuo

Tom
Super User Tom
Super User

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

;

woo
Barite | Level 11 woo
Barite | Level 11

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

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!

SAS Enterprise Guide vs. SAS Studio

What’s the difference between SAS Enterprise Guide and SAS Studio? How are they similar? Just ask SAS’ Danny Modlin.

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
  • 6 replies
  • 1076 views
  • 3 likes
  • 4 in conversation