BookmarkSubscribeRSS Feed
mnew
Calcite | Level 5
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!
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
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]
mnew
Calcite | Level 5
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

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 756 views
  • 0 likes
  • 2 in conversation