SORTEDBY= Data Set Option

Specifies how a data set is currently sorted.
Valid in: DATA step and PROC steps
Category: Data Set Control

Syntax

SORTEDBY=by-clause </ collate-name> | _NULL_

Syntax Description

by-clause < / collate-name>
indicates how the data is currently sorted.
by-clause
names the variables and options that you use in a BY statement in a PROC SORT step.
collate-name
names the collating sequence that is used for the sort. By default, the collating sequence is that of your operating environment. A slash (/) must precede the collating sequence.
Operating Environment Information: For details about collating sequences, see the SAS documentation for your operating environment.
_NULL_
removes any existing sort indicator.

Details

SAS determines whether a data set is already sorted by the key variable or variables in ascending order by checking the sort indicator. The sort indicator is stored in the data set descriptor information and is set from a previous sort. For detailed information about how the sort indicator is used and how it improves performance, see The Sort Indicator in SAS Language Reference: Concepts and SORTVALIDATE System Option in SAS System Options: Reference.
The following example of the CONTENTS procedure Sort Information section containing the Validated attribute set to NO, indicates that the data set was sorted using the SORTEDBY= data set option.
  Sort Information
   Sortedby var1
   Validated NO
   Character Set ANSI

Comparisons

  • Use the CONTENTS statement in the DATASETS procedure to see how a data set is sorted.
  • The SORTEDBY= option indicates how the data is sorted, but does not cause a data set to be sorted.

Example

This example uses the SORTEDBY= data set option to specify how the data are currently sorted. The data set ORDERS is sorted by PRIORITY and by the descending values of INDATE. Once the data set is created, the sort indicator is stored with it. These statements create the data set ORDERS and record the sort indicator:
libname mylib 'SAS-library';
options yearcutoff=1920;
data mylib.orders(sortedby=priority 
                  descending indate);
   input priority 1. +1 indate date7.
         +1 office $ code $;
   format indate date7.;
   datalines;
1 03may01 CH J8U
1 21mar01 LA M91
1 01dec00 FW L6R
1 27feb99 FW Q2A
2 15jan00 FW I9U
2 09jul99 CH P3Q
3 08apr99 CH H5T
3 31jan99 FW D2W
;

See Also

DATASETS Procedure in Base SAS Procedures Guide
SORT Procedure in Base SAS Procedures Guide
SQL Procedure in SAS SQL Procedure User's Guide