BookmarkSubscribeRSS Feed
GN0001
Barite | Level 11

Hello team,

 

I am doing an inner join. 

I have one left table and 4 right tables,

I need to do inner joins with these 4 tables.

left table with first right table then output

left table with second right table then output

until the end,

but each time I do the joins, the second join should be with the rest of observations that

were not joined in the first attempt.

 

I hope this makes sense, if not, please let me know.

Respectfully,

blue

Blue Blue
1 REPLY 1
SASKiwi
PROC Star

If I understand your requirements correctly and assume that your 4 right tables have the same columns then something like this should work:

proc sql;
  create table want1 as

  select '1' as JoinNum
        ,*
  from Table1 as T1
  inner join table2 as T2
  on T1.key = T2.key

  union

  select '2' as JoinNum
        ,*
  from Table1 as T1
  inner join table3 as T2
  on T1.key = T2.key

  union

  select '3' as JoinNum
        ,*
  from Table1 as T1
  inner join table4 as T2
  on T1.key = T2.key

  union

  select '4' as JoinNum
        ,*
  from Table1 as T1
  inner join table5 as T2
  on T1.key = T2.key

  order by key, JoinNum
  ;
quit;

data want2;
  set want1;
  by key JoinNum;
  if first.key;
run;

The strategy is to do all 4 joins and to give each a priority. By sorting the 4 joins in priority order, you can ensure only the highest priority join is chosen.

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 Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 215 views
  • 1 like
  • 2 in conversation