Code missing datalines as unknown instead of missing

118 Views Asked by At

enter image description here

I am trying to recode the missing frequency counts to unknown and have 0 missing and place them in the unknown category instead. My code does not produce errors but it does not recode them as unknown

I tried using if/then statements to recategorize

1

There are 1 best solutions below

0
Richard On

Use the MISSING() function to detect missing values.

  if missing(gender) then gender='UNKNOWN';

This approach has problems though. If the recode value is longer than the variable, the recode value will be truncated.

If gender is $1, the assignment gender="UNKNOWN; will yield gender = 'U'.

A better approach is to use a custom format to map the missing value to your indicator.

proc format;
  value $missingc ' '='UNKNOWN';
  value  missingn  . ='UNKNOWN';
run;

proc freq data=have;
  table gender race ethnicity resident_or_staff age / missing;
  format gender race ethnicity resident_or_staff $missingC.;
  format age missingN.;
run;