import pointblank as pb
spss_missing = pb.MissingSpec.from_spss(
missing_values=[-99, -98, 99],
labels={-99: "Not asked", -98: "Refused"},
)
spss_missing.reasons{-99: 'not_asked', -98: 'refused', 99: 'missing_99'}
Create a MissingSpec from SPSS-style user-defined missing values.
Usage
SPSS supports up to 3 user-defined missing values per variable (plus a range). Pass the missing values (and optionally their value labels) to build a spec. Reason labels are derived from the labels when available, otherwise a "missing_<value>" placeholder is used. A range of missing values can’t be given, so list the values in the range that occur in the data.
missing_values: listThe sentinel values that SPSS marks as missing for the variable (e.g., [-99, -98]).
labels: dict[Any, str] | None = NoneOptional mapping of sentinel value to human-readable label (e.g., {-99: "Refused"}). Labels are slugified into reason identifiers (e.g., "Not asked" becomes "not_asked").
null_is_missing: bool = TrueWhether actual null values should also be treated as missing. Default is True.
null_reason: str = "unknown"The reason label for actual null values. Default is "unknown".
description: str | None = "SPSS user-defined missing values" MissingSpecimport pointblank as pb
spss_missing = pb.MissingSpec.from_spss(
missing_values=[-99, -98, 99],
labels={-99: "Not asked", -98: "Refused"},
)
spss_missing.reasons{-99: 'not_asked', -98: 'refused', 99: 'missing_99'}
The labels become the reasons "not_asked" and "refused". The value 99 has no label, so its reason is the placeholder "missing_99". To read the missing values and labels straight from an SPSS file, use import_metadata() and from_variable_metadata() instead.