Specifying expressions (BEGIN EXPR-END EXPR command)

Expressions for temporal causal model scenarios

You can create expressions for computing scenario values for use with the TCM ANALYSIS command. The structure of a BEGIN EXPR-END EXPR block for defining scenario expressions is as follows:

BEGIN EXPR
/OUTFILE PREPXML='filespec'.
COMPUTE statements
END EXPR.
  • You can include multiple expressions, each for a different scenario, in a single BEGIN EXPR-END EXPR block. Each expression can be defined by a single COMPUTE statement or by a set of coupled COMPUTE statements. Coupled statements are evaluated in the order in which they are specified, as is the case for any sequence of COMPUTE statements.
  • Each variable in an expression must either exist in the active dataset and be an input or target in the model system, or be defined by a prior COMPUTE statement in the BEGIN EXPR-END EXPR block.
  • You cannot reassign a variable in a COMPUTE statement. For example, you cannot specify COMPUTE advertising=1.1*advertising.

Example

This example specifies expressions for two scenarios that are based on the same root field advertising.

BEGIN EXPR
/OUTFILE PREPXML='/scenarios/myscenarios.xml'.
COMPUTE advert_10_pct = 1.1*advertising.
COMPUTE advert_20_pct = 1.2*advertising.
END EXPR.
  • The first COMPUTE statement defines a scenario whose values are 10 percent larger than the values of the root field. The second COMPUTE statement defines a scenario whose values are 20 percent larger than the values of the root field.
  • The target variable of each COMPUTE statement identifies the expression and is used in the TCM ANALYSIS command to reference the expression.

Expressions for custom simulation models

You can create expressions that define custom simulation models for use with the SIMPLAN command. A custom simulation model consists of a set of equations that specify the relationship between a set of targets and a set of inputs. The relationship between each target and its associated inputs is specified with a COMPUTE statement. In addition, variable definition commands must be provided for all input fields that do not exist in the active dataset. The structure of a BEGIN EXPR-END EXPR block for defining custom simulation models is as follows:

BEGIN EXPR
/OUTFILE PREPXML='filespec'.
NUMERIC or STRING statements
VARIABLE LEVEL statements
VALUE LABELS statements
COMPUTE statements
END EXPR.
  • You must include a NUMERIC or STRING statement to define each input that is not in the active dataset. Inputs that are in the active dataset, however, must not be included on NUMERIC or STRING statements. Targets (which can only be numeric) are defined by COMPUTE statements and do not need to be defined with NUMERIC statements.
  • By default, the measurement level for all targets and for all inputs not in the active dataset is continuous. Use VARIABLE LEVEL statements to specify the measurement level for targets and such inputs that are ordinal or nominal. For targets, the measurement level determines the set of output charts and tables that are generated. For inputs that will be simulated, the measurement level determines the default set of distributions used when fitting inputs to historical data.
  • Use VALUE LABELS statements to define any value labels for targets and for inputs that are not in the active dataset. Value labels are used in output charts and tables.
  • For inputs that are in the active dataset, measurement levels and value labels are taken from the active dataset. You can override the settings from the active dataset by specifying VARIABLE LEVEL and VALUE LABELS statements for those inputs, within the BEGIN EXPR-END EXPR block.
  • Use a separate COMPUTE statement for each equation in your model. The equations may be coupled but are evaluated in the order in which they are specified, as is the case for any sequence of COMPUTE statements.

Examples

This example creates a custom model based on an equation that relates the target revenue to the inputs price and volume, where volume is a field in the active dataset but price is not.

BEGIN EXPR
/OUTFILE PREPXML='/models/mymodel.xml'.
NUMERIC price.
COMPUTE revenue = price*volume.
END EXPR.

This example creates a custom model based on a set of three equations that specify profit as a function of both revenue and expenses. None of the inputs are fields in the active dataset.

BEGIN EXPR
/OUTFILE PREPXML='/models/mymodel.xml'.
NUMERIC price volume fixed unit_cost_materials unit_cost_labor.
COMPUTE revenue = price*volume.
COMPUTE expenses = fixed + volume*(unit_cost_materials + unit_cost_labor).
COMPUTE profit = revenue - expenses.
END EXPR.
  • The NUMERIC statement defines the five inputs that are used in the model since none of the inputs are fields in the active dataset.
  • Although revenue and expenses are inputs to profit, they are defined by COMPUTE statements, so they do not need to be defined by NUMERIC statements.
  • The COMPUTE statement for profit depends on revenue and expenses so the COMPUTE statements for revenue and expenses precede the one for profit.

Supported functions and operators

COMPUTE statements within BEGIN EXPR-END EXPR blocks support the following set of functions and operators for building expressions.

Table 1. Arithmetic operators and functions
Symbol or keyword Definition
+ Addition
- Subtraction
* Multiplication
/ Division
** Exponentiation
ABS Absolute value
EXP Exponential function
LG10 Base 10 logarithm
LN Natural logarithm
MAX Maximum of list
MIN Minimum of list
MOD Modulo
RND Round
SQRT Square root
TRUNC Truncation
& Logical AND
| Logical OR
~ Logical NOT
= Equal to
~= Not equal to
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
( ) Grouping

Alternative forms of relational operators, such as AND instead of &, are supported. For a complete list, see the section on Logical expressions.