Next: , Previous: Variable Short Names, Up: Variables

2.5.12 Variable Relationships

Variables have close relationships with dictionaries (see Dictionaries) and cases (see Cases). A variable is usually a member of some dictionary, and a case is often used to store data for the set of variables in a dictionary.

These functions report on these relationships. They may be applied only to variables that are in a dictionary.

— Function: size_t var_get_dict_index (const struct variable *var)

Returns var's index within its dictionary. The first variable in a dictionary has index 0, the next variable index 1, and so on.

The dictionary index can be influenced using dictionary functions such as dict_reorder_var (see dict_reorder_var).

— Function: size_t var_get_case_index (const struct variable *var)

Returns var's index within a case. The case index is an index into an array of union value large enough to contain all the data in the dictionary.

The returned case index can be used to access the value of var within a case for its dictionary, as in e.g. case_data_idx (case, var_get_case_index (var)), but ordinarily it is more convenient to use the data access functions that do variable-to-index translation internally, as in e.g. case_data (case, var).