Checking Ranges for Dates (Using a DATA Step)

Suppose you want to determine if the visit dates in the PATIENTS data set are between June 1, 1998 and October 15, 1999. You can use a DATA step approach, much the same way you did when checking that numeric variables were within a specified range. The only difference is that the range boundaries have to be SAS dates. Let’s see how this works. Program 4-1 checks for dates in the specified range and ignores missing values.

Program 4-1. Checking That a Date Is within a Specified Interval (DATA Step Approach)
LIBNAME CLEAN "C:\CLEANING"; DATA _NULL_; TITLE "Dates before June 1, 1998 or after October 15, 1999"; FILE PRINT; SET CLEAN.PATIENTS(KEEP=VISIT PATNO); IF VISIT LT '01JUN1998'D AND VISIT 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.