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;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 2 replies
  • 658 views
  • 0 likes
  • 2 in conversation