Hi,
I have a
dataset a: dataset b:
id size id size
1 3 2 4
2 4 3 6
3 5 4 6
4 6 5 7
5 7
I want to compare these two datasets and want an output, which says id 3 has different size when compared and id 2,4,5 has same size for both the datasets.
thank you!
data one;
input id size;
cards;
1 3
2 4
3 5
4 6
5 7
;
data two;
input id size;
cards;
2 4
3 6
4 6
5 7
;
proc sql;
create table diff_size as
select * from two
except
select * from one;
create table same_size as
select * from two
intersect
select * from one;
quit;
data a;
input id size ;
cards;
1 3
2 4
3 5
4 6
5 7
;
data b;
input id size;
cards;
2 4
3 6
4 6
5 7
;
proc sql;
create table want as
select a.*,ifc(a.size=b.size,'same','different') as remark
from a a,b b
where a.id=b.id;
quit;
Please try the below code
check the want dataset where size has value 1 indicating that for id=3 there is difference in size
data one;
input id size;
cards;
1 3
2 4
3 5
4 6
5 .
;
data two;
input id size;
cards;
2 4
3 6
4 6
5 7
;
proc compare base=one compare=two out=want listall;
id id;
run;
data one;
input id size;
cards;
1 3
2 4
3 5
4 6
5 7
;
data two;
input id size;
cards;
2 4
3 6
4 6
5 7
;
proc sql;
create table diff_size as
select * from two
except
select * from one;
create table same_size as
select * from two
intersect
select * from one;
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.