COMPARE Procedure

Overview: COMPARE Procedure

What Does the COMPARE Procedure Do?

The COMPARE procedure compares the contents of two SAS data sets, selected variables in different data sets, or variables within the same data set.
PROC COMPARE compares two data sets: the base data set and the comparison data set. The procedure determines matching variables and matching observations. Matching variables are variables with the same name or variables that you pair by using the VAR and WITH statements. Matching variables must be of the same type. Matching observations are observations that have the same values for all ID variables that you specify or, if you do not use the ID statement, that occur in the same position in the data sets. If you match observations by ID variables, then both data sets must be sorted by all ID variables.

What Information Does PROC COMPARE Provide?

PROC COMPARE generates the following information about the two data sets that are being compared:
  • whether matching variables have different values
  • whether one data set has more observations than the other
  • what variables the two data sets have in common
  • how many variables are in one data set but not in the other
  • whether matching variables have different formats, labels, or types
  • a comparison of the values of matching observations
Further, PROC COMPARE creates two kinds of output data sets that give detailed information about the differences between observations of variables that it is comparing.
The following example compares the data sets PROCLIB.ONE and PROCLIB.TWO, which contain similar data about students:
data'First Data Set');
   input student year $ state $ gr1 gr2;
   label year='Year of Birth';
   format gr1 4.1;
1000 1970 NC 85 87
1042 1971 MD 92 92
1095 1969 PA 78 72
1187 1970 MA 87 94

data proclib.two(label='Second Data Set');
   input student $ year $ state $ gr1
         gr2 major $;
   label state='Home State';
   format gr1 5.2;
1000 1970 NC 84 87 Math
1042 1971 MA 92 92 History
1095 1969 PA 79 73 Physics
1187 1970 MD 87 74 Dance
1204 1971 NC 82 96 French

How Can PROC COMPARE Output Be Customized?

PROC COMPARE produces lengthy output. You can use one or more options to determine the kinds of comparisons to make and the degree of detail in the report. For example, in the following PROC COMPARE step, the NOVALUES option suppresses the part of the output that shows the differences in the values of matching variables:
options nodate pageno=1 linesize=80 pagesize=40;
title 'The SAS System';
proc compare
             compare=proclib.two novalues;
Part one of Comparison of WORK.ONE and WORK.TWO.
Part two of Comparison of WORK.ONE and WORK.TWO.
Part three of Comparison of WORK.ONE and WORK.TWO.
Procedure Output shows the default output for these two data sets. Producing a Complete Report of the Differences shows the complete output for these two data sets.