Using Formats to Check for Invalid Values

Just as you did with character values in Chapter 1, you can use user-defined formats to check for out-of-range data values. Program 2-8 uses formats to find invalid data values, based on the same ranges used in Program 2-5 in this chapter.

Program 2-8. Detecting Out-of-Range Values Using User-Defined Formats
PROC FORMAT; VALUE HR_CK 40-100, . = 'OK'; VALUE SBP_CK 80-200, . = 'OK'; VALUE DBP_CK 60-120, . = 'OK'; RUN; DATA _NULL_; INFILE "C:\CLEANING\PATIENTS.TXT" PAD; FILE PRINT; ***Send output to the Output window; TITLE "Listing of Invalid Patient Numbers and Data Values"; ***Note: We will only input those variables of interest; INPUT @1 PATNO $3. @15 HR 3. @18 SBP 3. @21 DBP 3.; IF PUT(HR,HR_CK.) NE ...

Get Cody’s Data Cleaning Techniques Using SAS® Software 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.