Compare - print options

Reply
Occasional Contributor
Posts: 11

Compare - print options

Dear SAS experts,

 

I am new to SAS having fun learning it.

 

I am comparing two data sets with identical variables.  The rows from each data set are identified by three key variables. They are called, for example:

RGN_CD,

GRP_ID_NB,

SGRP_ID_NB

 

Below is my code.  Then SAS magically produces a row from each data set (one and two) and pair them up.  The result looks good.  As you see, I did not specifiy the keys in my code.  Can someone explain how SAS works in this case?  

 

two aditional questions: 1)  what option do I need to specify for the OUT in order to have SAS produce an additional row for the current pairs to mark the variables from the two data sets with different values?  

2) Is there a way to just have SAS print out the three keys and then the vairables with different values identified by those three keys?

 

Your kind help will be highly appreciated.  Also attached the sample output

 

Below is the code:

proc compare base=data_set_one
compare=data_set_two
out=outdiffpm outnoequal outbase outcomp noprint;
TITLE1 "Please Help Me SAS Community";

run;

ods html FILE="c:\diff_results.xls"
headtext="<style> td {mso-number-format:\@}</style>";

proc print data=outdiffpm;
run;

ods html close;

Super User
Posts: 11,134

Re: Compare - print options

Compare basically attempts to compare row 1 of one set with row 1 of the other. If the data is sorted by the same variables or happen to be in the same order then things work well. Resort one of the sets by a different set of variables and the results are not so good.

 

You can get a comparison of only selected variables by putting them on a VAR statement.

 

proc compare base=data_set_one
        compare=data_set_two
        out=outdiffpm outnoequal outbase outcomp noprint

 ;

   var RGN_CD GRP_ID_NB SGRP_ID_NB;

TITLE1 "Please Help Me SAS Community";
run;

 

You might have to show some dummy data of the two sets and the desired output as there may be more than one way to interpret your #2 request.

Occasional Contributor
Posts: 11

Re: Compare - print options

ok, that makes sense.  I did sort the two datasets by the 3 keys.  

 

What I would like to do is to print out only any variables that contains different values from the two sets.  Along with the keys.

 

I would like to have a line like call "diff" or something where I mark the variables with difference.  In my mock up, I just label them '99999999', or anything.

 

Thanks again, looks forward to your replies. 

Super User
Posts: 11,134

Re: Compare - print options

Instead of Outbase and Outcomp did you try Outdif?

Occasional Contributor
Posts: 11

Re: Compare - print options

Yes, I just tried your suggestions. I am getting now the third row which marks the variables with different values. thank you. very helpful as I am learning SAS on the fly,
Ask a Question
Discussion stats
  • 4 replies
  • 655 views
  • 1 like
  • 2 in conversation