LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (January 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Tue, 16 Jan 2007 12:38:47 -0500
Reply-To:     "data _null_;" <datanull@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         "data _null_;" <datanull@GMAIL.COM>
Subject:      Re: Safe way to test if a date is valid ?
Comments: To: Ya Huang <>
In-Reply-To:  <>
Content-Type: text/plain; charset=ISO-8859-1; format=flowed

This "old style" regex will verify the date is DDMMMYYYY but not if it is a valid SAS date. Perhaps a combination of this with INPUT DATE9 will suffice.

84 data _null_; 85 rx = rxparse('$d$d (jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec) $d$d$d$d');

86 87 do a='25MAY2OO6','25MAY2006','25APR2OO6','29FEB2003'; 88 valid = rxmatch(rx,trim(a)); 89 d=input(a,?date9.); 90 put _all_; 91 format d date.; 92 end; 93 call rxfree(rx); 94 run;

rx=1 a=25MAY2OO6 valid=0 d=25MAY02 _ERROR_=0 _N_=1 rx=1 a=25MAY2006 valid=1 d=25MAY06 _ERROR_=0 _N_=1 rx=1 a=25APR2OO6 valid=0 d=25APR02 _ERROR_=0 _N_=1 rx=1 a=29FEB2003 valid=1 d=. _ERROR_=1 _N_=1 rx=. a=29FEB2003 valid=1 d=. _ERROR_=1 _N_=1

On 1/16/07, Ya Huang <> wrote: > Hi there, > > I used to test if a character date is valid by testing with > a input function. If after input function I get a nonmissing value, > then the character date is valid. Until I saw a post by Paul Dorfman, a > while ago, showing that this is very dangerous: > > data _null_; > a='25MAY2OO6'; /* note here is OO, not 00 */ > d=input(a,date.); > put a d date.; > run; > > 25MAY2OO6 25MAY02 > > Now I'm wondering what else I can do to test if a character date > is valid without V9 funcy function, since I'm still using v8.12. > Another assumption is that character date is like DDMMMYYYY. > > Thanks > > Ya >

Back to: Top of message | Previous page | Main SAS-L page