1. Home
  2. TABSORT procedure

TABSORT procedure

Sorts tables so their margins are in ascending or descending order (R.W. Payne).


PRINT = string tokens Controls output (tables, histograms); default * i.e. none
DIRECTION = string token Direction of sorting (ascending, descending); default asce
METHOD = string token Method to use to construct a marginal table for the sorting of a factor when there is no one-way table classified by the factor in the TABLE list, and the first table in the TABLE list classified by the factor has no margins (totals, means, minima, maxima, variances, medians); default tota
FACTORS = pointer Specifies or saves a list of classifying factors of the tables in the TABLE list
NEWFACTORS = pointer Specifies or saves a list of classifying factors of the new tables, corresponding to those in the FACTORS pointer
EXCLUDE = pointer Factors to exclude from sorting
NBEST = string tokens Number of (best) levels to include from each sorted factor; default * i.e. all of them


TABLE = tables Tables to be sorted
NEWTABLE = tables Allows the new sorted tables to be saved
TITLE = texts Title to be used when displaying each table
FIELDWIDTH = scalars Field width for printing each table
DECIMALS = scalars Decimal places for each table


This procedure sorts tables so that their margins are in a specified order. With a multi-way table, for example, this may help in interpreting an interaction from an analysis of variance. With a one-way table, it allows the cells to be displayed in ascending order, as in a Pareto chart.

The original tables are supplied by the TABLE parameter. The NEWTABLE parameter can be used to save the sorted tables.

If you want to specify your own ordering, the FACTORS and NEWFACTORS options can be set to pointers of pre-defined factors indicating the ways in which each dimension of the tables is to be sorted: FACTORS contains factors from the classifying sets of the original tables, and NEWFACTORS contains the corresponding factors for the new tables (with the levels in the new order).

Alternatively, you can let TABSORT define the ordering. For each factor classifying the original tables, the ordering is obtained using a one-way table for that factor. This may be available amongst the list of original tables (specified by the TABLE parameter). If not, TABSORT finds the first table in the list with the factor in its classifying set. If the table has margins, then TABSORT will extract the appropriate one-way margin. Otherwise, it first constructs the margins using the MARGIN directive; the METHOD option then defines how the margin is formed (using means, medians and so on). Having obtained a suitable one-way table, TABSORT forms a new factor whose levels are in the order that will arrange the entries of the table in either ascending or descending order according to the setting of the DIRECTION option (default ascending). The FACTORS and NEWFACTORS options can then be used to save pointers containing the factors and reordered factors for future use. Note also, that even if you do not want to use the factors in future, you can use the pointers to specify identifiers for the new factors to be used when the tables are printed. (You must specify both of them, so that TABSORT can tell how the new identifiers correspond to the original factors.) The EXCLUDE option can be set to a pointer containing factors that are not to be re-ordered automatically, but should be left unchanged.

The NBEST option specifies the number of levels to include from each sorted factor. So, setting NBEST=5 would take only the first five levels in the sorted order. This may be useful if you have a large table, and want to show only the best part of the table (as defined by the sorting of the margins). This default is to include all of the levels.

The PRINT option controls the output produced by TABSORT. The setting tables prints the tables. The setting histograms, causes any one-way tables to be plotted by the DHISTOGRAM directive, and any two-way tables to be plotted by D3HISTOGRAM. The TITLE parameter allows you to supply a title to be used in the display of each table. The FIELDWIDTH parameter specifies field widths, and the DECIMALS parameter specified numbers of decimal places.




TABSORT uses FACSORT to sort the factors and COMBINE to reorder the table.

See also



Commands for: Calculations and manipulation, Six sigma, Survey analysis.


        'Data from Snedecor & Cochran (1980), Statistical Methods',\
        '(seventh edition), p.305.'; STYLE=meta,plain
FACTOR  [NVALUES=60; LABELS=!T(Beef,Cereal,Pork); VALUES=(1...3)20] Source
FACTOR  [NVALUES=60; LABELS=!T(High,Low); VALUES=3(1,2)10] Amount
READ    Gain
 73  98  94  90 107  49
102  74  79  76  95  82
118  56  96  90  97  73
104 111  98  64  80  86
 81  95 102  86  98  81
107  88 102  51  74  97
100  82 108  72  74 106
 87  77  91  90  67  70
117  86 120  95  89  61
111  92 105  78  58  82 :
TREATMENTS Source*Amount
ANOVA      [PRINT=means; FPROBABILITY=yes] Gain
AKEEP      Source*Amount; MEANS=SourceMeans,AmountMeans,SourceByAmountMeans
TABSORT    [PRINT=tables] SourceMeans,AmountMeans,SourceByAmountMeans
Updated on June 18, 2019

Was this article helpful?