Dear SAS community, I am trying to create a more elegant code. I want to joint 3 tables have1, have2 and have3. The problem is that have1 table does not have id2 as a variable and first I have to link table have1 and have2. The code below is working but I would like to have a more elegant code because I may want to link more than 3 tables.
proc sql;
create table want1
as select *,b.id2
from have1 as a
left join have2 as b on a.id1=b.id1;
create table want2
as select a.*, b.*
from want1 as a left join have3 as c
on a.id2=c.id2;
I tried something like this but it is not working because I do not have id2 in table have1. Could you please let me know what is the most concise code for this.
proc sql;
create table want
as select *,b.id2
from have1 as a
left join have2 as b on a.id1=b.id1
left join have3 as c on a.id2=c.id2; quit;
proc sql;
create table want
as select *
from have1 as a
left join have2 as b on a.id1=b.id1
left join have3 as c on b.id2=c.id2
;
quit;
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.
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.