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

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

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