BookmarkSubscribeRSS Feed
AP718
Obsidian | Level 7

From the below example please show how can I take the columns from T1.A and T1.B and join the T2.B column?

 

T1.A

T1.B

 

T2.A

T2.B

BLK

234

 

BLK

768

WHITE

123

 

WHITE

8765

BLUE

456

 

BLUE

234

     

T1.A

T1.B

T2.B

  

BLK

234

768

  

WHITE

123

8765

  

BLUE

456

234

  

 

 

2 REPLIES 2
Kurt_Bremser
Super User

You join on T1.A=T2.A, that's obvious, isn't it?

proc sql;
create table want as
select
  T1.A,
  T1.B,
  T2.B
from T1 left join T2
on T1.A = T2.A;
quit;
Patrick
Opal | Level 21

And because column B exists in both source tables you need to rename it for the target table as there can't be two columns with the same name in the same table. Below @Kurt_Bremser 's SQL amended accordingly.

proc sql;
  create table want as
    select
      T1.A,
      T1.B as T1_B,
      T2.B as T2_B
    from T1 left join T2
    on T1.A = T2.A
    ;
quit;

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 446 views
  • 2 likes
  • 3 in conversation