Sorted Data Sets
The Sort Indicator
What Is a Sort Indicator?
After a data set is sorted, a sort indicator is added to the data set descriptor information.
The sort indicator is updated without a permanent sort of the data set by using the
SORTEDBY= data set option. The Sortedby and Validated sort information is updated
when the SORTEDBY= data set option is used.
The sort indicator contains some or all of the following sort information of a SAS data
set:
• how the data set is sorted by which variable or variables
• whether the order for a variable is descending or ascending
• the character set used for character variables
• the collating sequence used for ordering character data
• collation rules if the data set is sorted linguistically
• whether there is only one observation for any given BY group (use of NODUPKEY
option)
• whether there are no adjacent duplicate observations (use of NODUPREC option)
• whether the data set is validated
The sort indicator is set when a data set is sorted by a SORT procedure, an SQL
procedure with an ORDER BY clause, a DATASETS procedure MODIFY statement, or
a SORTEDBY= data set option. If the SORT or SQL procedures were used to sort the
data set, which is being sorted by SAS, the CONTENTS procedure output indicates that
the Validated sort information is YES. If the SORTEDBY= data set option was used to
sort the data set, which is being sorted by the user, the CONTENTS procedure output
indicates the Validated sort information is set to NO and the Sortedby sort information
is updated with the variable or variables specified by the data set option.
Data sets can be sorted outside of SAS. In that case, you might use the SORTEDBY=
data set option or the DATASETS procedure MODIFY statement to add the sort order to
the sort indicator. In this case, they are not validated. For more information, see
“Validating That a Data Set Is Sorted” on page 603.
To view the sort indicator information, use the CONTENTS procedure or the
CONTENTS statement in the DATASETS procedure. The following three examples
show the sort indicator information in the CONTENTS procedure output.
Example 1: Using No Sorting
The first example is a data set created without any type of sort:
options yearcutoff=1920;
libname myfiles 'C:My Documents';
data myfiles.sorttest1;
input priority 1. +1 indate date7.
+1 office $ code $;
598 Chapter 25 • SAS Data Sets