Help using Base SAS procedures

value statement: missing value

Reply
Frequent Contributor
Posts: 100

value statement: missing value

Hi there. How to refer to missing character variable values in a value statement (e.g. for Proc format)?
I have no trouble with using . = 'missing salary' when the variable is numeric ... But could not figure out a way to say: if the value for Gender is missing, format as 'Pls review'. I have tried just using '' but it did not work (no error msg / simply did not recode).
Thanks!
SAS Super FREQ
Posts: 8,740

Re: value statement: missing value

Hi:
There's a difference between '' (quote quote) and ' ' (quote space quote) in the definition of a value to which a character format will apply. In addition with any user-defined format, you can use the keyword OTHER to "catch" all the values that do not fit into your categories.

The program below makes some data with missing values and bad values for the SEX variable from SASHELP.CLASS (using only a subset of rows). Consider the difference between using ' ' (quote space quote) in the format (report #1) and using OTHER in the format (report #2).

cynthia
[pre]
data class;
set sashelp.class;
if age = 11 then sex = ' ';
if age = 16 then sex = 'Z';
run;

proc format;
value $gend 'M' = 'Male'
'F' = 'Female'
' ' = 'Please Review';

value $altgend 'M' = 'Male'
'F' = 'Female'
other = 'Please Review';
run;

** only need to show a small subset;
proc sort data=class;
by sex;
where age in(11,12,16);
run;

proc print data=class;
format sex $gend.;
title '1 Using Space in format';
run;

proc print data=class;
format sex $altgend.;
title '2 Using OTHER in format';
run;
[/pre]
Frequent Contributor
Posts: 100

Re: value statement: missing value

This is great. You are exactly right. I thought just '' should be enough as missing character variable is blank in the dataset. I tried again with the space between quotes and it worked!

Agree on the benefit of using Other. There are times when I will need both missing and other. (For example, missing could be "to be assigned" and other could be "typo, please review".

Big Thanks!
mona
Ask a Question
Discussion stats
  • 2 replies
  • 113 views
  • 0 likes
  • 2 in conversation