Range Checking for Dates

You can also use PROC SQL to check for dates that are out of range. Suppose you want a list of all patients in the PATIENTS data set that have nonmissing visit dates before June 1, 1998 or after October 15, 1999. You use the same programming statements used for checking out-of-range numeric quantities except that you use a date constant in place of the actual number of days from January 1, 1960 (day 0 according to SAS). The SQL statements in Program 8-8 will do the trick.

Program 8-8. Using SQL to Perform Range Checks on Dates
PROC SQL; TITLE "Dates Before June 1, 1998 or After October 15, 1999"; SELECT PATNO, VISIT FROM CLEAN.PATIENTS WHERE VISIT NOT BETWEEN '01JUN1998'D AND '15OCT1999'D AND VISIT IS NOT MISSING; QUIT; ...

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.