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!
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;
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;
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!
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.
Ready to level-up your skills? Choose your own adventure.