Previous: RECODE, Up: Data Manipulation [Contents][Index]
SORT CASES BY var_list[({D|A}] [ var_list[({D|A}] ] ...
SORT CASES sorts the active dataset by the values of one or more
variables.
Specify BY and a list of variables to sort by. By default, variables
are sorted in ascending order. To override sort order, specify (D) or
(DOWN) after a list of variables to get descending order, or (A)
or (UP)
for ascending order. These apply to all the listed variables
up until the preceding (A), (D), (UP) or (DOWN).
The sort algorithms used by SORT CASES are stable. This means
records which have equal values of the sort variables have the
same relative order before and after sorting. Thus,
re-sorting an already sorted file does not affect the ordering of
cases.
SORT CASES is a procedure. It causes the data to be read.
SORT CASES attempts to sort the entire active dataset in main memory.
If workspace is exhausted, it falls back to a merge sort algorithm which
creates numerous temporary files.
SORT CASES may not be specified following TEMPORARY.
In Example 12.6 the data from the file physiology.sav is sorted by two variables, viz sex in descending order and temperature in ascending order.
get file='physiology.sav'. sort cases by sex (D) temperature(A). list. |
Example 12.6: Sorting cases by two variables.
In Results 12.4 you can see that all the cases with a sex of ‘1’ (female) appear before those with a sex of ‘0’ (male). This is because they have been sorted in descending order. Within each sex, the data is sorted on the temperature variable, this time in ascending order.
|
Results 12.4: The physiology.sav file after sorting.
Note that SORT CASES, like all other transformations, affects only the active file.
It does not have any effect upon the physiology.sav file itself. For that, you
would have to rewrite the file using the SAVE command (see SAVE).
Previous: RECODE, Up: Data Manipulation [Contents][Index]