As the first step in the decommissioning of the site has been converted to read-only mode.

Here are some tips for How to share your SAS knowledge with your professional network.

COMPARE procedure

From sasCommunity
(Redirected from PROC COMPARE)
Jump to: navigation, search

The COMPARE procedure allows two datasets to be compared for differences as well as allowing variables in the same dataset to be compared.


PROC COMPARE <options> ;
BY statement ;
ID statement ;
VAR statement ;
WITH statement ;
ATTRIB statement ;
FORMAT statement ;
LABEL statement ;
WHERE statement ;
<global statements> ;
RUN statement ;
Statements shown in italics are optional. Not all statements are necessary and some statements may be omitted or statement order may be changed. This could affect the behaviour of the procedure.


  • <options> can be used to specify the BASE and COMPARE datasets as well as specify how the procedure compares data and what sort of output is produced.
    • Dataset options can be used with each dataset to modify how the procedure views the datasets. These options do not normally affect the source datasets but can modify the output dataset(s).
  • The BY statement specifies the variable(s) to group the comparasons by. The datasets need to be sorted and grouped as specified in the BY statement, unless the NOTSORTED by option is specified.
  • The ID statement specifies the variable(s) that uniquely identify the observations to be compared. The datasets also needs to be sorted as specified in the ID statement, unless the NOTSORTED option is also specified. Duplicate ID values are able to be reported as comparison issues.
  • The VAR statement lists the variable(s) in the BASE dataset to be used when comparing the datasets.
  • The WITH statement lists the variable(s) in the COMPARE dataset to be used when comparing the datasets. If the WITH statement is used then the VAR statement also needs to be used, and the variable lists are compared based on the order the variables are listed in the two statements. If the WITH statement is omitted then the variables listed in the VAR statement need to appear in both datasets. The WITH and VAR statements must both be used if the COMPARE dataset is omitted.
  • The WHERE statement can be used to limit the comparison to a subset of records in the two tables. The WHERE dataset option may also be used to do this on a particular dataset.
  • Other statements should not affect how the procedure makes a comparison but could affect the nature or format of the output of the procedure.
  • While the procedure is often used to compare values, it can also compare formats and types. If the raw (unformatted) values of the compared variables are the same but the formats of the variables differ then a discrepancy may still be reported.

See also

Further reading

SAS documentation

Base SAS Procedures Guide: Version: 9.2