COMPARE Procedure

BY Statement

Produces a separate comparison for each BY group.
See: BY

Syntax

Required Argument

variable
specifies the variable that the procedure uses to form BY groups. You can specify more than one variable. If you do not use the NOTSORTED option in the BY statement, then the observations in the data set must be sorted by all the variables that you specify. Variables in a BY statement are called BY variables.

Optional Arguments

DESCENDING
specifies that the observations are sorted in descending order by the variable that immediately follows the word DESCENDING in the BY statement.
NOTSORTED
specifies that observations are not necessarily sorted in alphabetic or numeric order. The observations are grouped in another way (for example, chronological order).
Note:The requirement for ordering observations according to the values of BY variables is suspended for BY-group processing when you use the NOTSORTED option. The procedure defines a BY group as a set of contiguous observations that have the same values for all BY variables. If observations with the same values for the BY variables are not contiguous, then the procedure treats each contiguous set as a separate BY group.

Details

BY Processing with PROC COMPARE

To use a BY statement with PROC COMPARE, you must sort both the base and comparison data sets by the BY variables. The nature of the comparison depends on whether all BY variables are in the comparison data set and, if they are, whether their attributes match the ones of the BY variables in the base data set. The following table shows how PROC COMPARE behaves under different circumstances:
Condition
Behavior of PROC COMPARE
All BY variables are in the comparison data set and all attributes match exactly
Compares corresponding BY groups
None of the BY variables are in the comparison data set
Compares each BY group in the base data set with the entire comparison data set
Some BY variables are not in the comparison data set
Writes an error message to the SAS log and terminates
Some BY variables have different types in the two data sets
Writes an error message to the SAS log and terminates