SORT directive
Sorts units of vectors according to an index vector.
Options
Parameters
Description
The SORT directive allows you to reorder the units of a list of vectors or pointers according to one or more "index" vectors. These can be specified explicitly using the INDEX option (and they need not be among the vectors actually sorted). If you omit the INDEX option, GenStat uses the first vector in the OLDVECTOR list. The DECIMALS option allows you to define the number of decimal places that are taken into account for an index variate: for example DECIMALS=0 would round each value to the nearest integer. If you do not set this, there is no rounding. The DIRECTION option controls whether the ordering is into ascending or descending order; by default DIRECTION=ascending.
The vectors or pointers whose values are to be sorted are listed by the OLDVECTOR parameter. The units of each structure are permuted in exactly the same way, into an ordering determined from the index vectors. The NEWVECTOR parameter allows you to specify new vectors to contain the sorted values, and thus keep the unsorted values in the original vectors. For example
SORT [INDEX=Name] Age,Income,Name,Sex; NEWVECTOR=A,*,N,S
would place the sorted values of Age, Name and Sex into A, N and S; as there is a null entry (*) corresponding to Income in the NEWVECTOR list, the sorted incomes would replace the original values of Income. Any undeclared vector in the NEWVECTOR list is declared implicitly to match the corresponding OLDVECTOR.
Options: INDEX, DIRECTION, DECIMALS.
Parameters: OLDVECTOR, NEWVECTOR.
Action with
RESTRICT
You can restrict the index vector, or any of the oldvectors, to sort only a subset of the units. Each of the units that is not in the subset is left in its original position.