SORT

Options     Examples

SORT sorts the observations of a series in increasing order. Other series or all series currently defined may also be reordered in the same order as the first series.

SORT (ALL, REVERSE) <key series> [ <list of other series>] ;

or

SORT (AVETIES, MINTIES, RANK, REVERSE) <key series> <rank of series> ;

Usage

The simplest form is SORT followed by the name of a series to be sorted. A bubble sort is performed, so any equal values will not be reordered relative to each other.

To sort several series in the same order as the first, just list them in the command. To sort all currently defined series, use the ALL option. All series must have the same length.

To sort series individually, use a DOT loop:

DOT X Y Z;

     SORT . ;

ENDDOT;

To "sort" in random order, draw a random variable and sort based on its values.

To obtain the rank order of a series use the second form of the command. The options AVETIES and MINTIES specify how tied series are to be treated.

Output

There is no printed output, but the series are stored after reordering their observations.

Options

ALL/NOALL causes all currently defined series to be sorted in the order defined by the named series.

AVETIES/NOAVETIE specifies that the average rank is to be stored for tied series. Used with RANK option.

MINTIES/NOMINTIE specifies that the minimum rank is to be stored for tied series. Used with RANK option.

RANK/NORANK stores the ordinal rank of the first series in the second series (the order of the first series is not changed).

REVERSE/NOREVERS sorts in decreasing order.

Examples

If X = 20 40 30 50 10 and Y = 1 2 3 4 5 ,

SORT (RANK) X RX;           ? yields RX = 2 4 3 5 1 (and X is unchanged)

SORT X Y;                         ? yields X = 10 20 30 40 50 and Y = 5 1 3 2 4

SORT (ALL) X ;                  ? yields the same as the previous command

SORT (REVERSE) X;          ? yields X = 50 40 30 20 10