BookmarkSubscribeRSS Feed
Fluvio1
Calcite | Level 5

I am using Proc Compare to try and select the observations in one dataset, but not in the other, and output the observations.  There does not seem to be an out=   option that does this ?  Please advise.  Here is my code:

 


proc contents data=work.import_163;
run;
*proc print;
*run;
proc sort data=work.import_163;
by Wrs_acres;
run;

data Merge_148_163;
merge work.import_148 work.import_163 ;
by WRS_acres;
run;

Proc print data=Merge_148_163;
run;
proc contents data=Merge_148_163;
run;


proc compare base=work.import_163 compare=work.import_148
out=diff outnoequal noprint;
id wrs_acres;
run;


proc print data=diff ;
by wrs_acres;
id wrs_acres;
title 'The Output Data Set RESULT';
run;

 

2 REPLIES 2
Tom
Super User Tom
Super User

If you want to match the observations on the key variables then just use a data step to split the data into matching and non matching datasets.

So something like this.

data both left_only right_only;
  merge left(in=inleft) right(in=inright);
  by keys ;
  if inleft and inright then output both;
  else if inleft then output left_only;
  else output right_only;
run;

If you want EXACT matches then make the BY statement include ALL of the variables.

ballardw
Super User

The options would be OUTBASE if you want the observation from the BASE data set or OUTCOMP if you want them from the COMPARE set.

Note that a variable telling you which data set the observations come from is added:

data work.base;
   set sashelp.class;
run;

data work.comp;
   set sashelp.class;
   if sex='M' and name not in ('Alfred' 'Robert')then height=height+1;
run;

proc compare base=work.base compare=work.comp noprint
   out=work.different outnoequal outcomp;
run;

proc compare base=work.base compare=work.comp noprint
   out=work.different2 outnoequal outbase;
run;

You can run this as you should have the SASHELP.CLASS data set.

Since you did not provide any actual data or what you want to see from the result it is hard to tell if this actually matches your expectations.

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
  • 48 views
  • 2 likes
  • 3 in conversation