SORT CASES command sorts the cases in the data file by one or more variables. The order by which cases are sorted may be ascending (lower values first) or descending (higher values first). The variable(s) by which the cases are to be sorted is/are listed after the keyword
SORT CASES BY id.
More complex example:
SORT CASES BY region city (a) income (d).
SORTing cases may be necessary either because you want to have a close look at the data, or because some procedures - most notably MATCHing files - require the data to be sorted. The most common case surely will be to sort cases by a "identification variable" which serves to uniquely identify each case by a number, a name, or whatever. But instead, or in addition, the data may be sorted by any variable or combination of variables you wish.
By default, the cases will be sorted in ascending order of the sorting variable(s). However, in some cases it may be helpful to sort cases in descending order. This can be achieved by having the variable(s) followed by "(d)" in the
SORT CASES command. A mixture of ascending and descending order may be used as well, with "(a)" indicating ascending order. If there are several consecutive variables by which cases are to be sorted in the same order, only one ordering tag for all these variables is required.
Here's a few examples.
SORT CASES BY region city id.
Here, all cases will first be sorted by region. Within each region, cases will be sorted by city. Within each city, cases will be sorted by id. For all three sorting variables, cases that have lower values will come first (ascending order by default).
SORT CASES BY region city (a) unempl (d) id (a).
Here, all cases will first be sorted by region and, within regions, by city, both in ascending order. Within each city, cases will be sorted by variable "unempl" (say, duration of unemployment), with higher values of "unempl" coming first. If there are cases within a city with the same values in "unempl", cases with lower id will come first.
© W. Ludwig-Mayerhofer, IGSW | Last update: 23 Apr 1998