From: Joyce on
data _null_;
a='25MAY2OO6'; /* note here is OO, not 00 */

d=input(a,date9.);
if trim(left(a)) ^= put(d, date9.) then put 'ERROR: ' a d date.;

run;


On 1/16/07, Ya Huang <ya.huang(a)amylin.com> 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
>
From: Joyce on
hmmm
thats true.

jo

On 1/16/07, Nordlund, Dan (DSHS/RDA) <NordlDJ(a)dshs.wa.gov> wrote:
>
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of
> Joyce
> > Sent: Tuesday, January 16, 2007 12:05 PM
> > To: SAS-L(a)LISTSERV.UGA.EDU
> > Subject: Re: Safe way to test if a date is valid ?
> >
> > data _null_;
> > a='25MAY2OO6'; /* note here is OO, not 00 */
> >
> > d=input(a,date9.);
> > if trim(left(a)) ^= put(d, date9.) then put 'ERROR: ' a d date.;
> >
> > run;
> >
> >
> > On 1/16/07, Ya Huang <ya.huang(a)amylin.com> 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
> > >
>
> Joyce,
>
> Your suggestion will incorrectly raise an error when a date like
> '9MAY2006' (single-digit day value) or '25may2006' (lowercase month) is
> encountered.
>
> Dan
>
> Daniel J. Nordlund
> Research and Data Analysis
> Washington State Department of Social and Health Services
> Olympia, WA 98504-5204
>
From: "data _null_;" on
But you could fix that...

length c $9;
c = '0';
substr(c,1+vlength(c)-length(left(a)))=upcase(a);
if c ne put(d,date9.) then error 'ERROR: ' a= d=date9.;



On 1/16/07, Joyce <joycegeorge(a)gmail.com> wrote:
> hmmm
> thats true.
>
> jo
>
> On 1/16/07, Nordlund, Dan (DSHS/RDA) <NordlDJ(a)dshs.wa.gov> wrote:
> >
> > > -----Original Message-----
> > > From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of
> > Joyce
> > > Sent: Tuesday, January 16, 2007 12:05 PM
> > > To: SAS-L(a)LISTSERV.UGA.EDU
> > > Subject: Re: Safe way to test if a date is valid ?
> > >
> > > data _null_;
> > > a='25MAY2OO6'; /* note here is OO, not 00 */
> > >
> > > d=input(a,date9.);
> > > if trim(left(a)) ^= put(d, date9.) then put 'ERROR: ' a d date.;
> > >
> > > run;
> > >
> > >
> > > On 1/16/07, Ya Huang <ya.huang(a)amylin.com> 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
> > > >
> >
> > Joyce,
> >
> > Your suggestion will incorrectly raise an error when a date like
> > '9MAY2006' (single-digit day value) or '25may2006' (lowercase month) is
> > encountered.
> >
> > Dan
> >
> > Daniel J. Nordlund
> > Research and Data Analysis
> > Washington State Department of Social and Health Services
> > Olympia, WA 98504-5204
> >
>
From: Scott Barry on
FYI - A lowercase month was interpreted correctly with SAS on Windows and z/OS platforms.

Also, I would consider the SAS DATE INFORMAT processing of alpha-characters in the year to be an
serious defect without question. Hopefully SAS Institute can understand why, presuming someone
reported the behavior?

For many years I've used the DATA step technique with INPUT function and checking _ERROR_ to
validate a user-specified date string as being correct. To see Dan's post is disquieting.

Sincerely,

Scott Barry
SBBWorks, Inc.


> -----Original Message-----
> From: SAS(r) Discussion [mailto:S...(a)LISTSERV.UGA.EDU] On Behalf Of Joyce
> Sent: Tuesday, January 16, 2007 12:05 PM
> To: S...(a)LISTSERV.UGA.EDU
> Subject: Re: Safe way to test if a date is valid ?

> data _null_;
> a='25MAY2OO6'; /* note here is OO, not 00 */


> d=input(a,date9.);
> if trim(left(a)) ^= put(d, date9.) then put 'ERROR: ' a d date.;


> run;


> On 1/16/07, Ya Huang <ya.hu...(a)amylin.com> 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



Joyce,

Your suggestion will incorrectly raise an error when a date like '9MAY2006' (single-digit day value)
or '25may2006' (lowercase month) is encountered.


Dan


Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204
From: NordlDJ on
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L(a)LISTSERV.UGA.EDU] On Behalf Of Scott
> Barry
> Sent: Tuesday, January 16, 2007 2:20 PM
> To: SAS-L(a)LISTSERV.UGA.EDU
> Subject: Re: Safe way to test if a date is valid ?
>
> FYI - A lowercase month was interpreted correctly with SAS on Windows and
> z/OS platforms.
>
<<snip>>

Scott,

The problem was not that SAS wouldn't correctly input a date string with lower case letters, it was that the expression

if trim(left(a)) ^= put(d, date9.) then put 'ERROR: ' a d date.;

comparing the original input string with the formatted value after input would generate an error output for valid SAS dates where the month was in lower case or the day value was a single digit (i.e. no leading zero).

SAS can handle single-digit day values and lower-case months just fine.

Dan

Daniel J. Nordlund
Research and Data Analysis
Washington State Department of Social and Health Services
Olympia, WA 98504-5204