-2

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

vimuth
  • 5,064
  • 33
  • 79
  • 116
angel
  • 1
  • A single period would not be treated as missing value. SAS treats character values that only contain spaces as missing values. Are you sure your variables are character? If they are numeric you cannot store strings into them. – Tom Apr 29 '23 at 00:04
  • @vimuth, again, a reminder to close-vote questions that use images inappropriately instead of inlining their images. – starball May 01 '23 at 05:37

1 Answers1

2

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;
Richard
  • 25,390
  • 3
  • 25
  • 38