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.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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