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

I have two data sets with collective ID variables. That is, each of these variable may not be unique across the data set (i.e., duplicated), but together they form a unique set of ID. Suppose the first hypothetical data set looks like:

ID1          ID2          Var1          Var2         

Joe         A

Joe         B

Smith     A

Smith     C

Ann       D

The second hypothetical data set looks like:

ID1          ID2          Var3          Var4         

Joe         A

Wil         B

Smith     A

Smith     C

Ann       E

So how can I merge these variable using data step?

1 ACCEPTED SOLUTION

Accepted Solutions
gergely_batho
SAS Employee

proc sort data=data1;

     by ID1 ID2;

run;

proc sort data=data2;

     by ID1 ID2;

run;

data want;

     merge data1 data2;

     by ID1 ID2;

run;

View solution in original post

2 REPLIES 2
gergely_batho
SAS Employee

proc sort data=data1;

     by ID1 ID2;

run;

proc sort data=data2;

     by ID1 ID2;

run;

data want;

     merge data1 data2;

     by ID1 ID2;

run;

RW9
Diamond | Level 26 RW9
Diamond | Level 26

You can also use SQL joins, example:

proc sql;

  create table WANT as

  select  COALESCE(A.MAKE,B.MAKE) as MAKE,

          A.MODEL as BASE_MODEL,

          B.MODEL as COMP_MODEL

  from    SASHELP.CARS A

  full join SASHELP.CARS B

  on      A.MAKE=B.MAKE;

quit;

mysql - What's the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN and FULL JOIN? - Stack O...

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!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 2357 views
  • 0 likes
  • 3 in conversation