BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Shradha1
Obsidian | Level 7

I have two tables AC and DC, where the 'Account_Number' field is the merging key.

I want to do a left join on both these tables where table AC is the left table. But I want this join to happen only when the variable 'Month' in table AC takes value=5. But I want to retain all the observations of table AC and the new variables that are coming from table DC to AC will only have values in cases where Month=5.

 

Will this way work?

 

PROC SQL;
CREATE TABLE AC AS
SELECT A.*, B.* FROM AC(where=(month=5)) AS A
LEFT JOIN
DC AS B
ON A.KEY=B.KEY;
QUIT;

 

Please help. Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
tarheel13
Rhodochrosite | Level 12

I don't think I would write it that way. I would just use the where clause in SQL. If a and b have any of the same columns, SAS is going to put a warning in the log that the column exists in more than one table.

Proc SQL;
create table AC as 
select a.*,b.*
from ac as a 
left join 
dc as b
on a.key=b.key
where a.month=5;
quit;

View solution in original post

2 REPLIES 2
tarheel13
Rhodochrosite | Level 12

I don't think I would write it that way. I would just use the where clause in SQL. If a and b have any of the same columns, SAS is going to put a warning in the log that the column exists in more than one table.

Proc SQL;
create table AC as 
select a.*,b.*
from ac as a 
left join 
dc as b
on a.key=b.key
where a.month=5;
quit;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1489 views
  • 0 likes
  • 2 in conversation