BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Smitha9
Fluorite | Level 6

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

3 REPLIES 3
novinosrin
Tourmaline | Level 20

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;
Jagadishkatam
Amethyst | Level 16

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;
Thanks,
Jag
Ksharp
Super User
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;

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

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.

Discussion stats
  • 3 replies
  • 686 views
  • 0 likes
  • 4 in conversation