BookmarkSubscribeRSS Feed
Aayushi_17
Quartz | Level 8

How to compare to Two datasets and output the difference by using subject variable which is present in both domains using proc freq .

 

Dataset A;

subject 

123

232

234

120

001

 

DATASET B

subject 

123

232

234

 

2 REPLIES 2
Kurt_Bremser
Super User

If you just need to detect missing keys:

proc sort data=a;
by subject;
run;

proc sort data=b;
by subject;
run;

data
  both
  only_a
  only_b
;
merge
  a (in=in_a)
  b (in=in_b)
;
by subject;
if in_a and in_b
then output both;
else if in_a
then output only_a;
else output only_b;
run;

If you need more than that, look at PROC COMPARE.

ballardw
Super User

Why are you specifically stating the Proc Freq must be used? Proc freq takes a single data set as input.

 

Proc Compare is designed to compare data sets and can use BY processing to compare records based on values of common variables.

 

Your requirement of "output the difference by using subject variable" is not particularly clear as to the expected result.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 749 views
  • 2 likes
  • 3 in conversation