BookmarkSubscribeRSS Feed
janon
Calcite | Level 5

In this example, I have two tables (Table A and Table B) and I want to make a third table (Table C) which is basically Table A, and the addition of one column from Table B.

 

i.e.

Table A

Customer_IDCustomer_NameCustomer_Credit_Rating
1Jane3
2Josh8
3Jess8

 

Table B

Customer_IDFacility_IDSecurity_TypeLVR
1FAC115A88%
2FAC108A75%
8FAC109D80%
9FAC111E90%
10FAC113F80%

 

Makes Table C

Customer_IDCustomer_NameCustomer_Credit_RatingLVR
1Jane388%
2Josh875%
3Jess8null

 

How is this done? I have tried a left join but it results in Table C having more records than Table A.

 

Thanks in advance

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data a;
input Customer_ID Customer_Name $ Customer_Credit_Rating;
datalines;
1 Jane 3
2 Josh 8
3 Jess 8
;

data b;
input Customer_ID Facility_ID $ Security_Type $ LVR $;
datalines;
1 FAC115 A 88%
2 FAC108 A 75%
8 FAC109 D 80%
9 FAC111 E 90%
10 FAC113 F 80%
;

proc sql;
   create table want as
   select a.*, b.LVR
   from a left join b
   on a.Customer_ID = b.Customer_ID;
quit;
Kurt_Bremser
Super User

Whenever your code does not work as intended, post it and the log from it, so we can point out where you went wrong. Also supply data in usable form (data step with datalines), so we can test our code against exactly the same data that you used.

As has been shown already, the left join works, so you must have mixed up something.

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 763 views
  • 0 likes
  • 3 in conversation