Monday, March 6, 2017

Hack 4.15 Setting Multiple Variables to Missing in a Single Statement

SAS Programming Professionals,

Did you know that you can easily set one or more SAS variables to missing values in a single statement?

The CALL Missing SAS call routine allows you to set character and numeric variables to missing values.  Call Missing sets numeric variables to numeric missing (.), and character variables to character missing (blank).  The basic format is:

CALL MISSING(varname1<, varname2, ....>);

Here is an example:

data vetted_class;
set  sashelp.class;

if age < 14 then call missing(weight, height, sex);


In the example, we have specific criteria for setting variables to missing—when the subject is younger than 14 years old.  When that is the case, we set the values of weight, height, and sex to missing.  Note that weight and height are numeric variables, while sex is a character variable.  It makes no difference at all to CALL MISSING; it sets them all to missing!

Best of luck in all your SAS endeavors!

(aka Michael A. Raithel)
Author of the new cult classic for computer programmers:  It Only Hurts When I Hit <ENTER>
Print edition: 
Kindle edition: 

The hack above is an excerpt from the book:  Did You Know That?  Essential Hacks for Clever SAS Programmers

No comments:

Post a Comment