Uploaded by Shivram Janapareddy

Compare Procedure

advertisement
The COMPARE procedure:
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 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.
Syntax:
PROC COMPARE <option(s)>;
VAR variable(s);
WITH variable(s);
Run;
PROC COMPARE statement options:
BASE=
Specify the base data set
COMPARE=
Specify the comparison data set
data one(label='First Data Set');
input student year $ state $ gr1 gr2;
label year='Year of Birth';
datalines;
1000 1970 NC 85 87
1042 1971 MD 92 92
1095 1969 PA 78 72
1187 1970 MA 87 94
;
data two(label='Second Data Set');
input student $ year $ state $ gr1 gr2 major $;
label state='Home State';
datalines;
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
;
proc compare base=one compare=two ;
run;
Novalues
the NOVALUES option suppresses the part of the output that shows the differences in the
values of matching variables
proc compare base=one compare=two novalues;
run;
OUT=
Create an output data set
OUTALL
Write an observation for each observation in the BASE= and COMPARE= data sets
proc compare base=one compare=two out=comp outall;
run;
OUTBASE
Write an observation for each observation in the BASE= data set
proc compare base=one compare=two out=comp outbase;
run;
OUTCOMP
Write an observation for each observation in the COMPARE= data set
proc compare base=one compare=two out=comp outcomp;
run;
OUTDIF
Write an observation that contains the differences for each pair of matching observations
proc compare base=one compare=two out=comp outdif;
run;
OUTNOEQUAL
Suppress the writing of observations when all values are equal
proc compare base=one compare=two out=comp outnoequal;
run;
OUTPERCENT
Write an observation that contains the percent differences for each pair of matching
observations
proc compare base=one compare=two out=comp outpercent;
run;
Comparing Variables in Different Data Sets
VAR statement: It Compares Variables in Different Data Sets and it compares Variables That
Are in the Same Data Set.
WITH Statement: Compares variables in the base data set with variables that have different
names in the comparison data set, and compares different variables that are in the same data set.
Note: You must use the VAR statement when you use the WITH statement.
Following example compares a variable from the base data set with a variable in the comparison
data set.
proc compare base=one compare=two;
var gr1;
with gr1;
run;
NOSUMMARY
Suppress the summary reports
proc compare base=one compare=two nosummary;
var gr1;
with gr1;
run;
Comparing a Variable Multiple Times
This example compares one variable from the base data set with two variables in the comparison
data set.
proc compare base=one compare=two nosummary;
var gr1 gr1;
with gr1 gr2;
run;
Comparing Variables That Are in the Same Data Set
This example shows that PROC COMPARE can compare two variables that are in the same
data set.
proc compare base=one ;
var gr1 ;
with gr2;
run;
ALLSTATS
Print a table of summary statistics for all pairs of matching variables
proc compare base=one allstats;
var gr1;
with gr2;
run;
Download