Previous: Variable Auxiliary Data, Up: Variables


2.5.14 Variable Categorical Values

Some statistical procedures require a list of all the values that a categorical variable takes on. Arranging such a list requires making a pass through the data, so PSPP caches categorical values in struct variable.

When variable auxiliary data is revamped to support multiple clients as described in the previous section, categorical values are an obvious candidate. The form in which they are currently supported is inelegant.

Categorical values are not robust against changes in the data. That is, there is currently no way to detect that a transformation has changed data values, meaning that categorical values lists for the changed variables must be recomputed. PSPP is in fact in need of a general-purpose caching and cache-invalidation mechanism, but none has yet been designed and built.

The following functions work with cached categorical values.

— Function: struct cat_vals * var_get_obs_vals (const struct variable *var)

Returns var's set of categorical values. Yields undefined behavior if var does not have any categorical values.

— Function: void var_set_obs_vals (const struct variable *var, struct cat_vals *cat_vals)

Destroys var's categorical values, if any, and replaces them by cat_vals, ownership of which is transferred to var. If cat_vals is a null pointer, then var's categorical values are cleared.

— Function: bool var_has_obs_vals (const struct variable *var)

Returns true if var has a set of categorical values, false otherwise.