Next: , Previous: User-Missing Values, Up: Basic Concepts


2.4 Value Labels

Each variable has a set of value labels (see VALUE LABELS), represented as struct val_labs. A struct val_labs is essentially a map from union values to strings. All of the values in a set of value labels have the same width, which for a set of value labels owned by a variable (the common case) is the same as its variable.

Numeric and short string sets of value labels may contain any number of entries. Long string sets of value labels may not contain any value labels at all, due to a corresponding restriction in SPSS. In PSPP we could easily eliminate this restriction, but doing so would also require us to extend the system file format in an incompatible way, which we consider a bad tradeoff.

It is rarely necessary to interact directly with a struct val_labs object. Instead, the most common operation, looking up the label for a value of a given variable, can be conveniently executed through functions on struct variable. See Variable Value Labels, for details.

Function prototypes and other declarations related to missing values are declared in data/value-labels.h.

— Structure: struct val_labs

Opaque type that represents a set of value labels.

The most often useful function for value labels is val_labs_find, for looking up the label associated with a value.

— Function: char * val_labs_find (const struct val_labs *val_labs, union value value)

Looks in val_labs for a label for the given value. Returns the label, if one is found, or a null pointer otherwise.

Several other functions for working with value labels are described in the following section, but these are more rarely useful.