Next: , Previous: Variable Type and Width, Up: Variables

2.5.3 Variable Missing Values

A numeric or short string variable may have a set of user-missing values (see MISSING VALUES), represented as a struct missing_values (see User-Missing Values).

The most frequent operation on a variable's missing values is to query whether a value is user- or system-missing:

— Function: bool var_is_value_missing (const struct variable *var, const union value *value, enum mv_class class)
— Function: bool var_is_num_missing (const struct variable *var, double value, enum mv_class class)
— Function: bool var_is_str_missing (const struct variable *var, const char value[], enum mv_class class)

Tests whether value is a missing value of the given class for variable var and returns true if so, false otherwise. var_is_num_missing may only be applied to numeric variables; var_is_str_missing may only be applied to string variables. For string variables, value must contain exactly as many characters as var's width.

var_is_type_missing (var, value, class) is equivalent to mv_is_type_missing (var_get_missing_values (var), value, class).

In addition, a few functions are provided to work more directly with a variable's struct missing_values:

— Function: const struct missing_values * var_get_missing_values (const struct variable *var)

Returns the struct missing_values associated with var. The caller must not modify the returned structure. The return value is always non-null.

— Function: void var_set_missing_values (struct variable *var, const struct missing_values *miss)

Changes var's missing values to a copy of miss, or if miss is a null pointer, clears var's missing values. If miss is non-null, it must have the same width as var or be resizable to var's width (see mv_resize). The caller retains ownership of miss.


— Function: void var_clear_missing_values (struct variable *var)

Clears var's missing values. Equivalent to var_set_missing_values (var, NULL).

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

Returns true if var has any missing values, false if it has none. Equivalent to mv_is_empty (var_get_missing_values (var)).