Advanced tables and statistics > Other tabulation facilities > Sorting tables > Sorting rows
 
Sorting rows
Quick reference
To sort the rows of a table, type:
sort
on the a, sectbeg, flt, tab or l statement.
Sorting is usually done on the figures in the base column. To sort on a different column, type:
sortcol
on that element.
To define an unsorted element, axis or table in an otherwise sorted axis, table or run, type:
nosort
on that element, l or tab statement.
Example
The statement:
tab prefer sex;sort
produces a table of prefer by sex in which the product preferred by most people forms the first row, and the product preferred by fewest people is the last row.
For example:
 
Base
Male
Female
 
 
 
 
Suds
59
10
49
Bubbles
49
11
38
New Foam
35
7
28
Sparkle
30
6
24
Glow
18
8
10
Extra Glow
9
2
7
As you can see, sorting is done using the figures in the base column of the table. By chance, this means that the column for women is also sorted in descending order.
If you want to sort on, say, the second column of the table, just put the option sortcol on the appropriate element in the axis:
l sex
col 10;Base;Male;%sortcol;Female
If you want an axis to be sorted every time it is used as a row axis, you can place sort on the l statement. Alternatively, if the axis is always to be unsorted in an otherwise sorted run, place the keyword nosort on the l statement. Both these methods are quicker and easier than remembering to place sort/nosort on every tab statement which uses the axis.
See also
Sorting tables