Skip to content

15.7.5.3 Totals and Subtotals ​

CATEGORIES also controls display of totals and subtotals. By default, or with TOTAL=NO, totals are not displayed. Use TOTAL=YES to display a total. By default, the total is labeled “Total”; use LABEL="_label_ " to override it.

Subtotals are also not displayed by default. To add one or more subtotals, use an explicit category list and insert SUBTOTAL or HSUBTOTAL in the position or positions where the subtotal should appear. The subtotal becomes an extra row or column or layer. HSUBTOTAL additionally hides the categories that make up the subtotal. Either way, the default label is “Subtotal”, use SUBTOTAL="_label_ " or HSUBTOTAL="_label_ " to specify a custom label.

The following example syntax and output show how to use TOTAL=YES and SUBTOTAL:

CTABLES
    /TABLE freqOfDriving
    /CATEGORIES VARIABLES=freqOfDriving [OTHERNM, SUBTOTAL='Valid Total',
                                         MISSING, SUBTOTAL='Missing Total']
                                        TOTAL=YES LABEL='Overall Total'.
Count
1. How often do you usually drive a car or other motor vehicle?Every day4667
Several days a week1274
Once a week or less361
Only certain times a year130
Never540
Valid Total6972
Don't know8
Refused19
Missing Total27
Overall Total6999

By default, or with POSITION=AFTER, totals are displayed in the output after the last category and subtotals apply to categories that precede them. With POSITION=BEFORE, totals come before the first category and subtotals apply to categories that follow them.

Only categorical variables may have totals and subtotals. Scalar variables may be “totaled” indirectly by enabling totals and subtotals on a categorical variable within which the scalar variable is summarized. For example, the following syntax produces a mean, count, and valid count across all data by adding a total on the categorical region variable, as shown:

CTABLES /TABLE=region > monthDaysMin1drink [MEAN, VALIDN]
    /CATEGORIES VARIABLES=region TOTAL=YES LABEL='All regions'.
MeanCountValid N
20. On how many of the thirty days in this typical month did you have one or more alcoholic beverages to drink?RegionNE5.61409945
MW5.016541026
S6.023901285
W6.51546953
All regions5.869994209

By default, PSPP uses the same summary functions for totals and subtotals as other categories. To summarize totals and subtotals differently, specify the summary functions for totals and subtotals after the ordinary summary functions inside a nested set of [] following TOTALS. For example, the following syntax displays COUNT for individual categories and totals and VALIDN for totals, as shown:

CTABLES
    /TABLE isLicensedDriver [COUNT, TOTALS[COUNT, VALIDN]]
    /CATEGORIES VARIABLES=isLicensedDriver TOTAL=YES MISSING=INCLUDE.
CountValid N
D7a. Are you a licensed driver; that is, do you have a valid driver's license?Yes6379
No572
Don't know4
Refused44
Total69996951

基于 GNU PSPP 2.0.1 手册与入门教程整理