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

How can we use LEFT JOIN when we have more than 2 tables? PROC SQL equivalent code for the following merge statement code?l

Data abc;

merge a (in=X) b c;

by id;

if X;

run;

1 ACCEPTED SOLUTION

Accepted Solutions
SteveED
SAS Employee

@SASKiwi gives a good example of a 3 table join. 

 

The example @Ujjawal gave though is for a match-merge which would generate (potentially) different results. HERE is a link to a SUGI 30 paper highlighting the differences (there are many other papers as well).  There are reasons to use the different types of merge/joins depending on the need. 

 

Steve

View solution in original post

2 REPLIES 2
SASKiwi
PROC Star

proc sql

  create table abc as

  select *

  from a

  left join b

  on a.id = b.id

  left join c

  on a.id = c.id;

quit;

SteveED
SAS Employee

@SASKiwi gives a good example of a 3 table join. 

 

The example @Ujjawal gave though is for a match-merge which would generate (potentially) different results. HERE is a link to a SUGI 30 paper highlighting the differences (there are many other papers as well).  There are reasons to use the different types of merge/joins depending on the need. 

 

Steve

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
  • 34902 views
  • 4 likes
  • 3 in conversation