Overview (SORT VARIABLES command)

SORT VARIABLES sorts the variables in the active dataset based on the values of the selected dictionary attribute.

Basic Specification

The basic specification is the command name SORT VARIABLES followed by the name of a single dictionary attribute.

Syntax Rules

  • Only one dictionary attribute can be specified.
  • The BY keyword is optional.
  • You can explicitly request the default sort order (ascending) by specifying A or UP in parentheses after the attribute name. To sort variables in descending order, specify D or DOWN.

Sorting Options

Variables can be sorted based on the values of any one of the following dictionary attributes:

NAME. Sort variables by variable names. The primary sort is alphabetical, but trailing digits are sorted numerically within ties on the preceding part. For example, V2 comes before V10 in ascending order.

TYPE. Group variables by type (numeric or string) and sort string variables by defined width. In default ascending order, numeric variables come before string variables, and shorter string variables come before longer string variables.

FORMAT. Group variables by format (for example, Date, Dollar, String).

LABEL. Sort variables in alphabetical order by variable labels. In default ascending order, all variables without defined variable labels come before variables with defined variable labels. See the topic VARIABLE LABELS for more information.

VALUES. Sort variables by value labels. In default ascending order, all variables without defined value labels come before variables with defined value labels. See the topic VALUE LABELS for more information.

MISSING. Group variables by defined missing values. In default ascending order, all variables without defined missing values come before variables with defined missing values. See the topic MISSING VALUES for more information.

MEASURE. Sort variables by measurement level. The default ascending order is: nominal, ordinal, scale. See the topic VARIABLE LEVEL for more information.

ROLE. Sort variables by role. Some dialogs support predefined roles that can be used to pre-select variables for analysis. See the topic Overview (VARIABLE ROLE command) for more information.

COLUMNS. Sort variables by column width. Column width is the width of the column that displays the variable in Data View of the Data Editor. See the topic VARIABLE WIDTH for more information.

ALIGNMENT. Group variables by alignment. The default ascending order is: left, right, center. See the topic VARIABLE ALIGNMENT for more information.

ATTRIBUTE name. Sort variables by values of the specified custom variable attribute name. In default ascending order, all variables without values for the named attribute come before variables with values for the named attribute. See the topic VARIABLE ATTRIBUTE for more information.