Advanced tables and statistics > Other tabulation facilities > Sorting tables > Sorting at different levels > Sorting with netsort
 
Sorting with netsort
Quick reference
To create a sorted table of nets, type:
netsort[=spaces_per_level]
where space_per_level is the number of additional spaces to ident element texts at each level.
More information
The quickest way to define an axis which will create a sorted table of nets is to place the keyword netsort on the a or l statement (netsort is not valid on sectbeg, flt or tab statements) and the keyword sort on the a/sectbeg/flt/tab statement. When these two keywords are used in the same table, a net statement determines not only the level at which the net is to be created (that is whether it is a top level net, a subnet, a sub-subnet, and so on), but also the level at which the net and the elements it contains are to be sorted in relation to the other elements in the table. This means that nets at level one are sorted and, within them, nets at level two are sorted, and so on. Individual elements within a net are sorted too.
Netting shows how netsort determines the number of spaces by which each net and element text is indented. This is still the case when netsort is used in sorted tables. Texts at each level below level one are indented by two spaces per level, thus nets at level two are indented by two spaces (1x2 spaces); nets at level three are indented by four spaces (2x2 spaces). The elements comprising a net are indented by an additional two spaces. You can request a different indent by typing netsort=n, where n is the number of spaces by which to indent, instead of netsort by itself.
To turn off indenting for a single table in a run where indenting is the default, add the option nonetsort or netsort=0 to the l statement of the table’s row axis.
Sometimes the axis will contain rows which are not to be sorted at all. These elements require the option nosort. If the element is part of a group, it will retain its original position in the group even if the group later occupies a different position in the sorted output. If the element is not part of any group, it will retain its original place regardless of any other elements.
Example
You have an axis dealing with peoples’ opinions of a new chocolate bar they have tried. Responses are netted under the headings Taste and Texture, and there is also a row to gather respondents giving no answer at all. Taste and texture are to be sorted so that the one containing the most respondents appears first. The No Answer row is to remain as the last row of the table.
Within taste and texture the various comments are to be sorted so that the one mentioned by most people is printed first. Each net contains a Don’t Know row which must always be the last line of the net. Element texts are to be indented by one space per net/sort level. To satisfy this specification, write:
tab taste brand;sort
l taste;netsort=1
n10Base (350)
net1Taste Observations (310)
n01Too Sweet;c=c220'1' (80)
n01Just Right;c=c220'2' (105)
n01Not Sweet Enough;c=c220'3' (95)
n01Don't Know;c=c220'4';nosort (30)
net1Texture Observations (340)
n01Too Coarse;c=c221'1' (60)
n01Just Right;c=c221'2' (125)
n01Too Fine;c=c221'3' (85)
n01Don't Know;c=c221'4';nosort (70)
netend1
n01No Answer;c=-;nosort (10)
The numbers in the parentheses are not part of the row specifications: they are the number of respondents giving each response.
How the groups are sorted
The sort is conducted on the first column (created by the first condition in the axis). Assume that this is the base, so the figures in parentheses are totals.
With Taste, all elements down to the net statement for Texture are assumed to be part of the same net and sort group. The result is:
Taste Observations 310
Just Right 105
Not Sweet Enough 95
Too Sweet 80
Don't Know 30
The same method of sorting applies to the Texture group, except that this time the net and sort group is terminated by the netend1 statement.
Then, the two groups are sorted in relation to each other. Since the net for Texture (340) is larger than the net for Taste (310), Texture Observations is placed first, without regard to the other values within either group. The final table is as follows:
Base 350 (This row is not part of any sort)
Texture Observations 340
Just Right 125
Too Fine 85
Too Coarse 60
Don't Know 70 (Always last within group because of
nosort)
Taste Observations 310
Just Right 105
Not Sweet Enough 95
Too Sweet 80
Don't Know 30
No Answer 10 (Last because of nosort on no1 statement)
The three elements which were specified with the nosort keyword have all retained their original places in relation to the other elements in their groups.
The texts at level one are not indented, whereas those at level two (the elements which make up the two nets) are indented by one space, as requested with netsort.
Net and sort groups may be made up of any number of rows and may themselves be subdivided into smaller groups. This is called nesting. Suppose the taste and texture nets refer to the chocolate topping on a cake, and the axis also has comments about the body of the cake itself. This gives two main groups for sorting (the topping and the cake); each has two sublevels: the taste and the texture.
This is specified as follows:
l taste;netsort
n10Base (142)
net1Chocolate Topping (Net) (27)
n01Not Sweet Enough;c=c121'2' (19)
net2Texture Observations (Sub-net) (41)
n01Too Course;c=c122'1' (20)
n01Too Fine;c=c122'2' (21)
net1Cake (Net) (50)
net2Taste Observations (Sub-net) (48)
n01Too Sweet;c=c123'1' (22)
n01Not Sweet Enough;c=c123'2' (26)
net2Texture Observations (Sub-net) (44)
n01Too Course;c=c124'1' (20)
n01Too Fine;c=c124'2' (24)
and produces the following table:
 
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
If an n33 statement is read immediately after a net statement, it is assumed to be in the same sort and indent level as the net. Therefore, if the text of the first net2 element was entered as:
net2Taste Observations on
n33the Chocolate Topping (Sub-net)
both lines would be indented by two spaces in the table.
If the axis contains an ntt to create a text-only net element, the elements in the ntt group are sorted although the group as a whole, including the ntt element, will retain its original position in the axis. To illustrate this, add a group of miscellaneous comments to the end of the previous axis:
l taste;netsort
n10Base
net1Chocolate Topping (Net)
net2Taste Observations (Sub-net)
n01Too Sweet;c=c121'1'
n01Not Sweet enough;c=c121'2'
net2Texture Observations (Sub-net)
n01Too Course;c=c122'1'
n01Too Fine;c=c122'2'
net1Cake (Net)
net2Taste Observations (Sub-net)
n01Too Sweet;c=c123'1'
n01Not Sweet enough;c=c123'2'
net2Texture Observations (Sub-net)
n01Too Course;c=c124'1'
n01Too Fine;c=c124'2'
netend1
n01No Mentions;c=c(121,124)$ $;nosort
ntt1Miscellaneous Mentions
n01Other topping observations;c=c121'3/&'.or.c122'3/&'
n01Other cake observations;c=c123'3/&'.or.c124'3/&'
The table which this axis produces 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