Next: COUNT, Previous: AUTORECODE, Up: Data Manipulation [Contents][Index]
COMPUTE variable = expression.
or
COMPUTE vector(index) = expression.
COMPUTE
assigns the value of an expression to a target
variable. For each case, the expression is evaluated and its value
assigned to the target variable. Numeric and string
variables may be assigned. When a string expression’s width differs
from the target variable’s width, the string result of the expression
is truncated or padded with spaces on the right as necessary. The
expression and variable types must match.
For numeric variables only, the target variable need not already
exist. Numeric variables created by COMPUTE
are assigned an
F8.2
output format. String variables must be declared before
they can be used as targets for COMPUTE
.
The target variable may be specified as an element of a vector (see VECTOR). In this case, an expression index must be specified in parentheses following the vector name. The expression index must evaluate to a numeric value that, after rounding down to the nearest integer, is a valid index for the named vector.
Using COMPUTE
to assign to a variable specified on LEAVE
(see LEAVE) resets the variable’s left state. Therefore,
LEAVE
should be specified following COMPUTE
, not before.
COMPUTE
is a transformation. It does not cause the active dataset to be
read.
When COMPUTE
is specified following TEMPORARY
(see TEMPORARY), the LAG
function may not be used
(see LAG).