Log 5.2 SAS Log Results for a Missing Value in a Statistic Function
143 data test;
144 x=.;
145 y=5;
146 a=x+y;
147 b=sum(x,y);
148 c=5;
149 c+x;
150 put a= b= c=;
151 run;
a=. b=5 c=5
NOTE: Missing values were generated as a result of performing an operation on
missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 146:6
NOTE: The data set WORK.TEST has 1 observations and 5 variables.
NOTE: DATA statement used (Total process time):
real time 0.12 seconds
cpu time 0.01 seconds
Adding X and Y together in an expression produces a missing result because the value of
X is missing. The value of A, therefore, is missing. However, since the SUM function
ignores missing values, adding X to Y produces the value 5, not a missing value.
Note: The SUM statement also ignores missing values, so the value of C is also 5.
For more information about functions, see “SAS Functions and CALL Routines by
Category” in SAS Functions and CALL Routines: Reference.
Working with Missing Values
How to Represent Missing Values in Raw Data
The following table shows how to represent each type of missing value in raw data so
that SAS reads and stores the value appropriately.
Table 5.2 Representing Missing Values
Missing Values Representation in Data
Numeric
. (a single decimal point)
Character
' ' (a blank enclosed in quotation marks)
Special
.letter (a decimal point followed by a letter, for example, .B)
Special
._(a decimal point followed by an underscore)
Working with Missing Values 89
How to Set Variable Values to Missing in a DATA Step
You can set values to missing within your DATA step by using program statements such
as this one:
if age<0 then
age=.;
This statement sets the stored value of Age to a numeric missing value if Age has a value
less than 0.
Note: You can display a missing numeric value with a character other than a period by
using the DATA step's MISSING statement or the MISSING= system option.
The following example sets the stored value of Name to a missing character value if
Name has a value of “none”:
if name="none" then name='';
Alternatively, if you want to set to a missing value for one or more variable values, you
can use the CALL MISSING routine. For example:
call missing(sales, name);
This sets both variable values to a missing value.
Note: You can mix character and numeric variables in the CALL MISSING routine
argument list.
How to Check for Missing Values in a DATA Step
You can use the N and NMISS functions to return the number of nonmissing and
missing values, respectively, from a list of numeric arguments.
When you check for ordinary missing numeric values, you can use code that is similar to
the following:
if numvar=. then do;
If your data contains special missing values, you can check for either an ordinary or
special missing value with a statement that is similar to the following:
if numvar<=.z then do;
To check for a missing character value, you can use a statement that is similar to the
following:
if charvar=' ' then do;
The MISSING function enables you to check for either a character or numeric missing
value, as in:
if missing(var) then do;
In each case, SAS checks whether the value of the variable in the current observation
satisfies the condition specified. If it does, SAS executes the DO group.
Note: Missing values have a value of false when you use them with logical operators
such as AND or OR.
90 Chapter 5 Missing Values

Get SAS 9.4 Language Reference, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.