Working with Missing Values


How to Represent Missing Values in Raw Data

Table 6.2 on page 107 shows how to represent each type of missing value in raw data so that SAS will read and store the value appropriately.

Table 6.2: Representing Missing Values

These missing values

Are represented by

Explanation

Numeric

.

a single decimal point

Character

' '

a blank enclosed in quotes

Special

.letter

a decimal point followed by a letter, for example, .B

Special

._

a decimal point followed by an underscore

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); 

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.




SAS 9.1.3 Language Reference. Concepts
SAS 9.1.3 Language Reference: Concepts, Third Edition, Volumes 1 and 2
ISBN: 1590478401
EAN: 2147483647
Year: 2004
Pages: 258

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net