FACSORT procedure
Sorts the levels of a factor according to an index vector (R.W. Payne).
Options
Parameters
Description
This procedure reorders the levels of a factor. The factor is specified by the FACTOR parameter. The NEWFACTOR parameter can specify the identifier for the new reordered factor (so that FACTOR is left unchanged). If this is not supplied, the original FACTOR is redefined with its levels in the new order.
The order is defined by an index vector, specified by the INDEX parameter. This can be a variate, or a text, or a one-way table, whose number of values is equal to the number of levels of the factor. The levels are thus sorted in parallel with the INDEX (using the SORT directive), and the DIRECTION option indicates whether this is to be into ascending or descending order.
The SETATTRIBUTES option specifies which of the labels, levels and values to define for the NEWFACTOR. If SETATTRIBUTES is not set, the default is to define whichever of these has been defined for the FACTOR. In particular, note that levels are then not defined if the FACTOR levels are simply 1,2...
The NEWLEVELS parameter can specify a variate to save the levels of the NEWFACTOR. You can use this as the setting of the OLDPOSITIONS and NEWPOSITIONS parameters of the COMBINE directive in order to reorder tables classified by the factor. Or, you can discover the (ordinal) number of the original level corresponding to each new level by
GETATTRIBUTE [ATTRIBUTE=levels] FACTOR; SAVE=FacLev
CALCULATE OldLevelNumber\
= POSITION(NEWLEVELS; FacLev['levels'])
Options: DIRECTION, SETATTRIBUTES.
Parameters: FACTOR, INDEX, NEWFACTOR, NEWLEVELS.
Method
FACSORT uses the standard GenStat manipulation commands, such as SORT.
Action with
RESTRICT
Any restrictions are ignored.