SORT records the BY variables, collating sequence, and character set
that it uses to sort the data set. This information is stored with
the data set to help avoid unnecessary sorts.
Before PROC SORT sorts
a data set, it checks the stored sort information. If you try to
sort a data set how it is currently sorted, then PROC SORT does not
perform the sort and writes a message to the log to that effect. To
override this behavior, use the FORCE option. If you try to sort a
data set how it is currently sorted and you specify an OUT= data set,
then PROC SORT simply makes a copy of the DATA= data set.
To override the sort
information that PROC SORT stores, use the _NULL_ value with the SORTEDBY=
data set option. Refer to the SORTEDBY= Data Set Option in SAS Data Set Options: Reference
If you want to change
the sort information for an existing data set, then use the SORTEDBY=
data set option in the MODIFY statement in the DATASETS procedure.
For more information, see MODIFY Statement.
To access the sort information
that is stored with a data set, use the CONTENTS statement in PROC
DATASETS. For more information, see CONTENTS Statement.
The number of variables
by which you can sort a data set with PROC SORT is limited only by
available memory. The number of columns by which you can order the
rows of a result set using PROC SQL, is also limited only by available
memory. The sort indicator, whether stored in the metadata of a
Base data set or represented in memory, is limited to 127 variables.
For this reason, up to 127 variables can be stored in the sort indicator
or listed on the SORTEDBY= data set option. If you are sorting by
more than 127 variables, then only the first 127 are recorded in the
sort indicator. If you sort the data set again by the entire list
of BY variables, then the data set will not be recognized as being
sorted, because the additional variables (beyond 127) are not found
within the sort indicator. For a detailed explanation, refer toWhat Is a Sort Indicator? in SAS Language Reference: Concepts.