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

Morning

 

I need urgent help, how do you do a join or data step merge in sas between two tables that have multiple columns that must be merged otherwise if you merge on just the one result the data table that gets created breaks and provided a number of rows that is higher than the initial table to which you do a left join.

 

Note that I need to merge at most three columns across two tables that share the exact same three columns with the table in the left join having more columns than the other table.

 

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

Example:

 

proc sql;
     create table want as select
          a.*,b.var1,b.var2,b.var3,b.var4
          /* type whatever variable names you want here instead of the fake names I used */
     from dataset1 a left join dataset2 b 
         on a.id1=b.id1 and a.id2=b.id2 and a.id3=b.id3;
         /* type whatever variable names you want here instead of the fake names I used */
quit;
--
Paige Miller

View solution in original post

3 REPLIES 3
PaigeMiller
Diamond | Level 26

Example:

 

proc sql;
     create table want as select
          a.*,b.var1,b.var2,b.var3,b.var4
          /* type whatever variable names you want here instead of the fake names I used */
     from dataset1 a left join dataset2 b 
         on a.id1=b.id1 and a.id2=b.id2 and a.id3=b.id3;
         /* type whatever variable names you want here instead of the fake names I used */
quit;
--
Paige Miller
Kamohelo_A
Calcite | Level 5

THANKS FOR THE HEADS UP

Kamohelo_A
Calcite | Level 5

Never mind. I resolved it using the following:

PROC SQL;
CREATE TABLE DATA_1 AS
SELECT DATA_INITIAL_1.* , OTHER_DATA.COLUMN5
FROM DATA_INITIAL_1
LEFT JOIN
OTHER_DATA
ON DATA_INITIAL_1.COLUMN1 = OTHER_DATA.COLUMN1
AND DATA_INITIAL_1.COLUMN2 = OTHER_DATA.COLUMN2
AND DATA_INITIAL_1.COLUMN3 = OTHER_DATA.COLUMN3
AND DATA_INITIAL_1.COLUMN4 = OTHER_DATA.COLUMN4;
QUIT;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

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

Browse our catalog!

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