SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

PROC SQL Joins on 3 Tables

Accepted Solution Solved
Reply
Regular Contributor
Posts: 183
Accepted Solution

PROC SQL Joins on 3 Tables

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;


Accepted Solutions
Solution
‎08-30-2017 10:41 AM
SAS Employee
Posts: 12

Re: PROC SQL Joins on 3 Tables

@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


All Replies
Super User
Posts: 3,252

Re: PROC SQL Joins on 3 Tables

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;

Solution
‎08-30-2017 10:41 AM
SAS Employee
Posts: 12

Re: PROC SQL Joins on 3 Tables

@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

☑ This topic is solved.

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

Discussion stats
  • 2 replies
  • 3784 views
  • 3 likes
  • 3 in conversation