Checking for Invalid Values: A DATA Step Approach (Setting Invalid Values to Missing) - SAS Programming

When you have raw data that you want to turn into a SAS data set,and you want to change the format in which some of the data values are stored,you can do it in one of two ways.You can either read the data as they occur in their raw form,insert them into the SAS data set you are building,and then change the values via conditional assignment statements, or you can "prescreen" the raw data on the way into the data set and make changes to the values before they are stored as SAS variable values.

The latter method is usually used for efficiency purposes. In this example, you use both methods.First, you read raw data into a SAS data set as they appear and change the stored values.Then you use an alternative method to change the data as they are being read in.

Suppose you have data coded as 'M' for male and 'F' for female, and you want to set all values other than 'M' or 'F' to a missing value (blank). A straightforward way to do this is to simply supply some logic statements in the DATA step as follows:

Example

DATA SCREEN4 ;
INPUT ID 1-3
GENDER $ 4 ... ;
IF GENDER NOT IN ('M','F')
THEN GENDER = ' ';
*

The IF statement with the IN operator as shown is equivalent to:

IF GENDER NOT='M' AND GENDER NOT='F' THEN GENDER=' ';

The result of this code is that all values of GENDER other than 'M' or 'F',including missing values (' '), are first read into data set SCREEN4,and then changed into a missing value (blank).Each value already coded as blank is "changed" into itself.


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

SAS Programming Topics