Overview (SORT CASES command)
SORT CASES reorders the sequence of cases in the active dataset based on the
values of one or more variables. You can optionally sort cases in
ascending or descending order, or you can use combinations of ascending
and descending order for different variables.
Basic Specification
The basic specification is a variable or list of variables that are used as sort keys. By default, cases are sorted in ascending order of each variable, starting with the first variable that is named. For each subsequent variable, cases are sorted in ascending order within categories of the previously named variables.
Syntax Rules
- Keyword
BYis optional. -
BYvariables can be numeric or string but not scratch, system, or temporary variables. - You
can explicitly request the default sort order (ascending) by specifying
AorUPin parentheses after the variable name. To sort cases in descending order, specifyDorDOWN. - An order specification
(
AorD) applies to all variables in the list, up to the previous order specification. If you combine ascending and descending order on the sameSORT CASEScommand, you may need to specify the defaultAexplicitly.
Operations
-
SORT CASESfirst sorts the file according to the first variable that is named. For subsequent variables, cases are sorted within categories of the previously named variables. - The sort sequence is based on the locale-defined
order (and is not necessarily the same as the numerical order of the
character codes). The default locale is the operating system locale. You can change the locale with SET LOCALE. Use
SHOW LOCALEto display the current locale.
- This procedure uses the multithreaded options specified
by
SET THREADS.
Limitations
- You cannot specify more than 64 sort variables.