Tables and axes > Filtering groups of tables > Nested filter sections in table specs
 
Nested filter sections in table specs
Quick reference
To mark the start of a nested filter section, type:
sectbeg[; c=logical_expression] [;options]
To mark the end of a nested filter section, type:
sectend
More information
Sometimes, you’ll have a group of tables which share the same overall set of titles and filters, but some tables within the group will require additional titles and filters. If you use flt statements, you’ll define the filters and titles for the first group and then repeat them, with the additional titles, for the second group. A more efficient method is to write a nested table spec.
In a nested table spec, you define your tables in groups or sections. The outermost group has filters and titles which apply to all tables in that group and also to any table subgroups which can occur in the group. Inner groups have just their additional filters and titles defined in their specs, but when Quantum creates the tables it will take the filters and titles for the outer group(s) first and then apply the additional filters and titles required for the subgroup.
As an example, suppose you have a set of tables for people who bought a new car during the last six months. You then want a second group of tables for women who bought a new VW car during that period. The basic titles and filters are the same — bought a new car during the last six months — but there are extra titles and filters for the second set of tables, namely, women who bought VWs. Therefore, you have two sections for filtering. The top level or section is people who bought new cars during the last six months, the lower level or subsection is the women who bought VWs.
The statements associated with this facility are sectbeg and sectend. To start a section, type:
sectbeg; options
where options is any of the options permitted on a, flt and tab statements, except dp and netsort. To end a section, type:
sectend
You can use up to ten sectbeg statements before using a sectend, but you must be certain that you include one sectend for every sectbeg used. The use of consecutive sectbeg statements without an intervening sectend signals a subsection within the main section. This ends at the first sectend, leaving the main section to continue until another sectend (with no further sectbeg statements) is read.
Note You cannot use a flt statement within a nested filter section; that is, between the sectbeg and sectend statements.
Having defined your filter requirements with sectbeg, you then enter titles and tab statements as usual. Here’s the spec for the new car buyers:
/* Force table titles to be printed last
a;op=12;dsp;ttend=tab
ttc J.1234: 1991 Car Buyers Study
/* General tables with no filters or subsections
tab age sex
tab make region
/* Start of new car buyers section
sectbeg; c=c123'1' .and. month .le. 6
ttlBought a new car in the last six months
tab make region
tab reason ban1
tab problems make
/* Start of subsection for female VW buyers
sectbeg; c=c109'2' .and. c130'5'
ttlWomen who bought a new VW
tab reason ban1
ttlReason for buying VW
tab likes ban1
ttlWhat likes about car
tab dislikes ban1
ttlWhat dislikes about car
/* End of subsection for female VW buyers
sectend
/* End of new car buyers section
sectend
The comments in the spec explain where each section starts and ends. When Quantum reaches the second sectbeg statement, it knows that it hasn’t yet read a sectend statement to terminate the first section, so it assumes that this is the start of a table subsection. Any filters or options on the second sectbeg plus any titles defined after it are applied to the tables in that section in addition to filters and titles already in place for the main section. The table of likes by ban1 will have four titles:
J.1234: 1991 Car Buyers Study
Bought a new car in the last six months
Women who bought a new VW
What likes about car
ttend=tab on the a statement prints titles in this order rather than printing filter titles after table titles.
If you wanted to write the same spec using flt statements, you’d need one flt statement for each sectbeg, containing the full filter specification for the next set of tables, followed by a listing of all titles required for those tables. For the tables in the subsections, this would mean repeating titles that were already defined for previous tables.
See also
Filtering groups of tables