BookmarkSubscribeRSS Feed
Agent1592
Pyrite | Level 9

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; 

 

1 REPLY 1
SASKiwi
PROC Star
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; 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 3852 views
  • 1 like
  • 2 in conversation