Advanced tables and statistics > Other tabulation facilities > Sorting tables > Sorting at different levels > Sorting with subsort and endsort
 
Sorting with subsort and endsort
Quick reference
To sort the table in sections, define the start of each section with:
subsort
on the first element in the section. Mark the end of the section with:
endsort[=num_sections]
where num_sections is the number of sections that this element terminates.
More information
The second way of specifying sorted nets is to use the keywords subsort and endsort to mark the start and end of each sort group in the axis. Although this involves you in more work, it can be useful when you want to use different amounts of indentation for different sort levels; for example, to indent all second-level elements by 1 space and all third-level elements by 2 spaces.
If you rewrite the first netsort example, it becomes:
tab taste brand;sort
l taste
n10Base
net1Taste Observations
n01 Too Sweet;c=c220'1';subsort
n01 Just Right;c=c220'2'
n01 Not Sweet Enough;c=c220'3'
n01 Don't Know;c=c220'4';nosort;endsort
net1Texture Observations
n01 Too Coarse;c=c221'1';subsort
n01 Just Right;c=c221'2'
n01 Too Fine;c=c221'3'
n01 Don't Know;c=c221'4';nosort;endsort
netend1
n01No Answer;c=-;nosort
The differences between this example and the previous version are as follows:
netsort has been removed from the l statement.
All indentation has been done manually by preceding each element text with a space.
The start of each subgroup has been identified by subsort.
The end of each subgroup has been identified by endsort.
There is no need to mark the top-level sort groups (that is, the net and No Answer elements), because these are sorted automatically by the keyword sort on the tab statement.
Groups defined with subsort and endsort may be nested up to a depth of seven levels of sorting; that is, you can type up to seven subsorts before typing an endsort to terminate one of the groups. If one row terminates more than one group, endsort must be entered as endsort=n where n is the number of groups terminated. If you rewrite the specification for Figure 31.1, it becomes:
l taste
n10Base
net1Chocolate Topping (Net)
net2 Taste Observations (Sub-net);subsort
n01 Too Sweet;c=c121'1';subsort
n01 Not Sweet Enough;c=c121'2';endsort
net2 Texture Observations (Sub-net)
n01 Too Coarse;c=c122'1';subsort
n01 Too Fine;c=c122'2';endsort=2
net1Cake (Net)
net2 Taste Observations (Sub-net);subsort
n01 Too Sweet;c=c123'1';subsort
n01 Not Sweet Enough;c=c123'2';endsort
net2 Texture Observations (Sub-net)
n01 Too Coarse;c=c124'1';subsort
n01 Too Fine;c=c124'2';endsort=2
The top level of sorting is between the rows ‘Chocolate Topping’ and ‘Cake’. The topping net has two sublevels, each of which is delimited by the keywords subsort and endsort. The row entitled ‘Too Fine’ in the Texture subnet terminates the texture subsort as well as the sort between taste and texture observations in general, so use endsort=2 to indicate that you are terminating two levels of sorting.
Text-only nets with ntt work with subsort and endsort exactly the same as with netsort, except that the elements within the net will require subsort and endsort keywords if they are to be sorted within the net.
If you indent second-level texts by one space and third-level texts by two spaces, the specification becomes:
tab taste brand;sort
l taste
n10Base
net1Chocolate Topping (Net)
net2 Taste Observations (Sub-net);subsort
n01 Too Sweet;c=c121'1';subsort
n01 Not Sweet enough;c=c121'2';endsort
net2 Texture Observations (Sub-net)
n01 Too Course;c=c122'1';subsort
n01 Too Fine;c=c122'2';endsort=2
net1Cake (Net)
net2 Taste Observations (Sub-net);subsort
n01 Too Sweet;c=c123'1';subsort
n01 Not Sweet enough;c=c123'2';endsort
net2 Texture Observations (Sub-net)
n01 Too Course;c=c124'1';subsort
n01 Too Fine;c=c124'2';endsort=2
netend1
n01No Mentions;c=c(121,124)$ $;nosort
ntt1Miscellaneous Mentions
n01 Other topping observations;c=c121'3/&'.or.c122'3/&';subsort
n01 Other cake observations;c=c123'3/&'.or.c124'3/&';endsort
and the table produced is:
 
Total
 
 
Base
142
Cake (Net)
50
Taste Observations (Sub-net)
48
Not Sweet Enough
26
Too Sweet
22
Texture Observations (Sub-net)
44
Too Fine
24
Too Course
20
Chocolate Topping (Net)
47
Taste Observations (Sub-net)
46
Too Sweet
27
Not Sweet enough
19
Texture Observations (Sub-net)
41
Too Fine
21
Too Course
20
No Mentions
80
Miscellaneous Mentions
 
Other cake observations
35
Other topping observations
29
See also
Sorting at different levels