BookmarkSubscribeRSS Feed
Ranjeeta
Pyrite | Level 9
proc compare base=HT_ORIG_2017_subset  compare=HT_NEW_2017_subset out=check outnoequal outdif outstats=diffstat noprint;

id CIHI_KEY;

var HOMETIME AWAYTIME ;

   with HOMETIME AWAYTIME;

  

   title 'Comparison of Variables in Different Data Sets';

run;

 

 

I get  the check dataset with 34 obs – are these 34 obs the only obs that have a different value for the 2 var variables specified in the var statement  in the 2 datasets?

And the diffstat has the stats produces for the 2 var variables for the 678 obs in the 2 datasets  specified in main and compare

How would I instead produce the same stats for the 34 obs ?

3 REPLIES 3
blueskyxyz
Lapis Lazuli | Level 10
data data1_dif;
	merge check(where=(base) in=a) data1;
	by keyvars;
	if a;
run;

/*pick the different obs*/
data data2_dif;
	merge check(where=(base) in=a) data2;
	by keyvars;
	if a;
run;

/*compare indirectly*/
proc compare b=data1_dif c=data2_dif  OUT=OUTCOMP LISTALL OUTBASE OUTCOMP OUTDIFF OUTNOEQUAL OUTSTATS=diffstat;
run;
Ranjeeta
Pyrite | Level 9
Hello

What is the where base variable?
Are data 1 and data 2 the 2 datasets that I am comparing
Is the check dataset the one that I created using the code above?
blueskyxyz
Lapis Lazuli | Level 10
/*1. first compare directly*/
proc compare base=data1  compare=data2  OUT=OUTCOMP1 LISTALL OUTBASE OUTCOMP OUTDIFF OUTNOEQUAL OUTSTATS=diffstat;
id CIHI_KEY;
var HOMETIME AWAYTIME ;
with HOMETIME AWAYTIME; /*can drop this line since variable name is same as var statements*/
run;

/*pick the different obs*/
/*keyvars: CIHI_KEY, to distinguish each unique record in your datasets */

data data1_dif;
	merge OUTCOMP1 (where=(base) in=a) data1;
	by keyvars;
	if a;
run;

/*pick the different obs*/
data data2_dif;
	merge OUTCOMP1 (where=(base) in=a) data2;
	by keyvars;
	if a;
run;

/*2. second compare indirectly*/
proc compare b=data1_dif c=data2_dif  OUT=OUTCOMP2 LISTALL OUTBASE OUTCOMP OUTDIFF OUTNOEQUAL OUTSTATS=diffstat;
id CIHI_KEY;
var HOMETIME AWAYTIME ;
run;

Yes, it is better if you can upload sample datasets to testthe code

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
  • 3 replies
  • 571 views
  • 0 likes
  • 2 in conversation