The
invalueset function determines whether an item's current value is within the permissible ranges of a value set. In addition to specifying the
item_name, an optional argument,
value_set_name, allows you to specify in which value set to check if the item's value is within the permissible ranges. If no value set is specified, the item's current value set is used.
The function returns a logical value of 1 (true) if the item's value is within the value set's ranges and 0 (false) otherwise. If the item has no value set, the function return 1 (true).
If you've included
Special Values in your valueset, but you'd rather exclude them in certain situations, you can accomplish this with a call to the
Special Function. In the example below, we want to see if the expected educational attainment agrees with the person's age, and issue an error message if it does not.
PROC P12_EDUCATION
if invalueset(AGE) and !special(AGE) then
recode AGE :: $ -> numeric age_agrees_with_education;
< 5 :: 0 -> true; // for ages 0-4, no educ attainment expected
5-10 :: 1 -> true; // for ages 5-10, primary attainment expected
11-16 :: 2 -> true; // for ages 11-16, secondary attainment expected
16 :: 0,1,2 -> true; // for ages 17+, any educ attainment allowed
-> false; // any other combination is incorrect
endrecode;
if age_agrees_with_education = false then
errmsg("Inconsistency between age (%d) and educ attainment (%d)", AGE, $);
endif;
endif;