Next: , Previous: , Up: Variables   [Contents][Index]


2.5.8 Variable Leave Status

Commonly, most or all data in a case come from an input file, read with a command such as DATA LIST or GET, but data can also be generated with transformations such as COMPUTE. In the latter case the question of a datum’s “initial value” can arise. For example, the value of a piece of generated data can recursively depend on its own value:

COMPUTE X = X + 1.

Another situation where the initial value of a variable arises is when its value is not set at all for some cases, e.g. below, Y is set only for the first 10 cases:

DO IF #CASENUM <= 10.
+ COMPUTE Y = 1.
END IF.

By default, the initial value of a datum in either of these situations is the system-missing value for numeric values and spaces for string values. This means that, above, X would be system-missing and that Y would be 1 for the first 10 cases and system-missing for the remainder.

PSPP also supports retaining the value of a variable from one case to another, using the LEAVE command (see LEAVE in PSPP Users Guide). The initial value of such a variable is 0 if it is numeric and spaces if it is a string. If the command ‘LEAVE X Y’ is appended to the above example, then X would have value 1 in the first case and increase by 1 in every succeeding case, and Y would have value 1 for the first 10 cases and 0 for later cases.

The LEAVE command has no effect on data that comes from an input file or whose values do not depend on a variable’s initial value.

The value of scratch variables (see Scratch Variables in PSPP Users Guide) are always left from one case to another.

The following functions work with a variable’s leave status.

Function: bool var_get_leave (const struct variable *var)

Returns true if var’s value is to be retained from case to case, false if it is reinitialized to system-missing or spaces.

Function: void var_set_leave (struct variable *var, bool leave)

If leave is true, marks var to be left from case to case; if leave is false, marks var to be reinitialized for each case.

If var is a scratch variable, leave must be true.

Function: bool var_must_leave (const struct variable *var)

Returns true if var must be left from case to case, that is, if var is a scratch variable.


Next: Dictionary Class, Previous: GUI Attributes, Up: Variables   [Contents][Index]