DATA Step, Macro, Functions and more

Question About joins in PROC sql

Reply
Contributor
Posts: 43

Question About joins in PROC sql

Suppose i have 3 tables:
My query is essentially
Select *
From T1
Inner join T2 on T1
Inner join T3 on T2
Where T1.filter = somefilter.

I understand T2 will join into the filtered T1 because of the where statement. Does T3 join on the newly filtered T2(because of T1), or will it try to join T2 as if it is unfiltered

Esteemed Advisor
Posts: 5,475

Re: Question About joins in PROC sql

Your ON join-conditions are not syntactically correct. They should read ON T1.something1 = T2.something2

PG
Contributor
Posts: 43

Re: Question About joins in PROC sql

Thanks. I know my joints aren’t correct from a syntax perspective. I was just asking from a conceptual perspective. I.e. can I join 1 and 2 and then 3 and 2 in one join
PROC Star
Posts: 2,311

Re: Question About joins in PROC sql

[ Edited ]

@mrdlau   > can I join 1 and 2 and then 3 and 2 in one join
Yes you can.  And any other combination.

 

Why even ask? As @kiranv_ said, just try it.

You'll have the answer faster, and you'll learn better.

PROC Star
Posts: 503

Re: Question About joins in PROC sql

best way to understand by  making up data and try out various scenarios. This will tremendously increase your knowledge. check with on clause initially then try where clauses. Nothing better than learning by doing.

Super User
Posts: 9,874

Re: Question About joins in PROC sql

And while you're doing your tests, as @kiranv_ suggested, also try a solution with sort and data steps, where you do the joins piecemeal.

With larger datasets, the overall performance might surprise you.

Caveat: This is only possible with 1-to-many, not with many-to-many relationships, where SQL is needed for the cartesian join.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Ask a Question
Discussion stats
  • 5 replies
  • 105 views
  • 2 likes
  • 5 in conversation