If I have the following two datasets:
data set ONE:
ID X
1 a
2 .
3 c
6 a
data set TWO:
ID Y
1 a
2 b
5 d
6 e
Here's the output I am looking for:
ID X Y
2 . b
3 c .
5 . d
6 a e
Is there a way to do this in PROC SQL?
So if X & Y are the same you delete the record? In that case this would work, assuming your input data is sorted by ID.
data want;
merge one two;
by ID;
if x = y then delete;
run;
proc sql;
create table want as
select coalesce(t1.ID, t2.ID) as ID, X, Y
from ONE as t1
full join TWO as t2
on t1.id = t2.id
where x ne y;
quit;
So if X & Y are the same you delete the record? In that case this would work, assuming your input data is sorted by ID.
data want;
merge one two;
by ID;
if x = y then delete;
run;
proc sql;
create table want as
select coalesce(t1.ID, t2.ID) as ID, X, Y
from ONE as t1
full join TWO as t2
on t1.id = t2.id
where x ne y;
quit;
data ONE;
input ID X $;
cards;
1 a
2 .
3 c
6 a
;
data TWO;
input ID Y $;
cards;
1 a
2 b
5 d
6 e
;
proc sql;
create table want as
select coalesce(a.id,b.id) as id,x,y
from
(select * from one except select * from two) as a
full join
(select * from two except select * from one) as b
on a.id=b.id;
quit;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.