PCOMPUTE Subcommand (CTABLES command)

In addition to displaying the aggregated results of summary statistics, a table can display one or more categories computed from those aggregated results and/or constant values. These are known as computed categories or postcomputes and are specified by the PCOMPUTE subcommand.

 /PCOMPUTE &catname= EXPR(expression)

The left side of the equation specifies the computed category name, which must be a valid name preceded by an ampersand (&). (For more information about valid names, see the topic Variable Names .) If two or more PCOMPUTE subcommands specify the same category name, the last one takes precedence. Computed categories cannot be referenced in a table expression or in the expression for another computed category.

The right side of the equation defines the expression used to calculate the postcomputed category. The expression is calculated for each summary statistic and can consist of:

  • References to category values. These are enclosed in brackets and must be quoted if they are strings or dates (for example, [1] or ['Male']). All categories in an expression must be of the same type (numeric, string, or date). Both valid and user-missing values are allowed.
  • Arithmetic operators. The supported operators are - (subtraction), + (addition), * (multiplication), / (division), and ** (exponentiation).
  • Parentheses. These are used to control the order of evaluation.
  • Numeric constants. Constants can be used by themselves (for example, &x=EXPR(50) or as part of a larger expression (for example, &x=EXPR(([1] + [2]) * 0.8)).
  • Keywords. The following keywords are supported in the expression: LO, THRU, HIGH, MISSING, and OTHERNM. If a range is specified, it must appear in square brackets (for example, &x=EXPR([LO THRU HIGH]) or &x=EXPR([1 THRU 5])). The values in the range are totaled.
  • References to totals and subtotals. If only one SUBTOTAL or HSUBTOTAL is used in a category list, the PCOMPUTE expression may refer to it by the SUBTOTAL keyword only or by keyword and position. (Both SUBTOTAL and HSUBTOTAL are referenced by the SUBTOTAL keyword in the computed category's expression.) If multiple subtotals are used, the expression must refer to them by position. The position is specified within square brackets following the keyword and must be an integer greater than or equal to 1 (for example, SUBTOTAL[2]). Totals are always referenced by keyword only.

All categories referenced in the expression must be also be explicitly specified in the CATEGORIES subcommand. As with other items in the table, the computed category's position in the CATEGORIES subcommand determines its position in the table.

By default, the values of computed categories use the same formatting for summary statistics as the other categories in the variable. ThePPROPERTIES subcommand allows you to specify different formatting. This subcommand also allows you to specify a label for the computed category and hide the categories used in the computed category's expression. See the topic PPROPERTIES Subcommand (CTABLES command) for more information.

Significance tests available on the SIGTEST and COMPARETEST subcommands are not computed for post-computed results.

Examples

CTABLES
  /PCOMPUTE &x=EXPR([2]-[1])
  /PPROPERTIES &x LABEL = "Female - Male"
  /TABLE SEX
  /CATEGORIES VARIABLES=SEX [1, 2, &x].
CTABLES
  /PCOMPUTE &x=EXPR([2]/[1])
  /PPROPERTIES &x LABEL = "Female / Male" FORMAT = COUNT F8.3
  /TABLE SEX
  /CATEGORIES VARIABLES=SEX [1, 2, &x].
CTABLES
  /PCOMPUTE &x = EXPR(SUBTOTAL[1] + SUBTOTAL[2])
  /PPROPERTIES &x LABEL="0-12"
  /TABLE educ[C]
  /CATEGORIES VARIABLES=educ [0 THRU 8, HSUBTOTAL="0-8", 9 THRU 12, HSUBTOTAL="9-12", &x, 
   OTHERNM, HSUBTOTAL=">12"] TOTAL=YES.