BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
NickC1
Calcite | Level 5

Hi Folks,

In PROC COMPARE is there any way to output (to a table) only the names of the variables where a value mismatch has been found between the two datasets?

So, not the variable values, just the name of the variable.

I have tried using OUT=table OUTNOEQUAL OUTDIF OUTBASE OUTCOMP but this outputs all the variables which have been compared, and I only want to see the names of variables which have a value mismatch.

 

For example, I am comparing two datasets with over 2500 variables, say 20 of these variables have unequal values, I want to extract only these variable names for use in a macro which I will create separate tables with obs pulled from both datasets to show the value differences.

 

I know I could use PRINTALL to display this in the log but I do not have enough programming experience to know how to interrogate the log to extract this information.

 

Is this possible? Or if I used all the OUT options above could anyone help me with the code to play find the "X" to extract the variable NAME where _TYPE_ = "DIF" from the output dataset?

 

I hope I have managed to make this question clear.  Many thanks for taking the time to read it!

 

1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

Something like this perhaps.

 

data class;
   set sashelp.class;
   if ranuni(3) lt .5 then do;
      weight = weight+1;
      height = height-1;
      sex    = lowcase(sex);
      end;

   run;
ods select none;
ods trace on;
proc compare novalues base=sashelp.class compare=class;
   ods output CompareSummary=CompareSummary;
   run;
ods trace off;
ods select all;
proc print;
   run;

data vars;
   set CompareSummary;
   retain keep 0;
   if type eq 'h' and strip(batch) eq 'Variables with Unequal Values' then keep=1;
   if keep;
   if type eq 'd' and not missing(batch);
   length var $32;
   var = scan(batch,1,' ');
   run;
proc print;
   run;

Capture.PNG

View solution in original post

4 REPLIES 4
sbxkoenk
SAS Super FREQ

I have read your post quickly and diagonally, but this may be what you want :

data work.a;
 set sashelp.class;
 if _N_=10 then height=27000;
run;

ODS TRACE OFF;
ODS OUTPUT CompareSummary=work.CompareSummary;
proc compare base=sashelp.class compare=work.a /* printall */;
   title 'Comparing Two Data Sets: Full Report';
run;

/* then look in the data set work.CompareSummary */

/* end of program */

Koen

data_null__
Jade | Level 19

Something like this perhaps.

 

data class;
   set sashelp.class;
   if ranuni(3) lt .5 then do;
      weight = weight+1;
      height = height-1;
      sex    = lowcase(sex);
      end;

   run;
ods select none;
ods trace on;
proc compare novalues base=sashelp.class compare=class;
   ods output CompareSummary=CompareSummary;
   run;
ods trace off;
ods select all;
proc print;
   run;

data vars;
   set CompareSummary;
   retain keep 0;
   if type eq 'h' and strip(batch) eq 'Variables with Unequal Values' then keep=1;
   if keep;
   if type eq 'd' and not missing(batch);
   length var $32;
   var = scan(batch,1,' ');
   run;
proc print;
   run;

Capture.PNG

NickC1
Calcite | Level 5

Brilliant, thank you! That is exactly what I need, very much appreciate the quick responses.

data_null__
Jade | Level 19

This is another way that may be useful. 

 

data class;
   set sashelp.class;
   if ranuni(3) lt .5 then do;
      weight = weight+1;
      height = height-1;
      sex    = lowcase(sex);
      end;
    run;
filename lst temp;
ods listing file=lst;
proc compare novalues brief base=sashelp.class compare=class;
   run;
ods listing close;

data vars;
   infile lst col=col;
   input @'NOTE: Values of the following' varnum @;
   input @'variables compare unequal:' @;
   do i = 1 to varnum;
      input variable:$32. @;
      output;
      end;
   stop;
   run;
proc print;
   run;

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 4 replies
  • 1742 views
  • 3 likes
  • 3 in conversation