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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.