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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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