Date: Thu, 29 Jun 2006 17:21:42 +0000
Reply-To: toby dunn <tobydunn@HOTMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: toby dunn <tobydunn@HOTMAIL.COM>
Subject: Re: Validating date date
In-Reply-To: <200606291656.k5TGTO4K019523@malibu.cc.uga.edu>
Content-Type: text/plain; format=flowed
If one has V9 you can do the following:
data q ;
x = "28/06/2006" ;
y = input( x , Anydtdte10. ) ;
put y= date9. ;
x = "31/06/2006" ;
y = input( x , Anydtdte10. ) ;
put y= date9. ;
run ;
I know Ian doesnt like the use of the AnyDtDte informat, but in this case it
does exactly what you want, it converts valid Date values to SAS Date
Values and if it isnt valid simply doesnt convert the value. the upside is
that it doesnt create any nasty notes in the log.
Toby Dunn
From: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
Reply-To: Gerhard Hellriegel <ghellrieg@T-ONLINE.DE>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Validating date date
Date: Thu, 29 Jun 2006 12:56:25 -0400
Like Toby said: the best way to test if a date is valid, try to convert it
and test the _error_ variable.
71 data q;
72 x="28/06/2006";
73 y=input(x,ddmmyy10.);
74 put y date9.;
75 x="31/06/2006";
76 y=input(x,ddmmyy10.);
77 put y date9.;
78 run;
28JUN2006
NOTE: Invalid argument to function INPUT at line 76 column 7.
.
x=31/06/2006 y=. _ERROR_=1 _N_=1
NOTE: Mathematical operations could not be performed at the following
places. The results of
the operations have been set to missing values.
Each place is given by: (Number of times) at (Line):(Column).
1 at 76:7
NOTE: The data set WORK.Q has 1 observations and 2 variables.
NOTE: DATA statement used (Total process time):
real time 0.04 seconds
cpu time 0.02 seconds
On Thu, 29 Jun 2006 15:56:19 +0000, toby dunn <tobydunn@HOTMAIL.COM> wrote:
>Jeli ,
>
>If you would convert your date values to SAS Date values two things will
>happen:
>
>1.) You will have a Data Value which you can actually work with
>
>2.) SAS wont convert an invalid text Date Value to a SAS Date Value.
>
>
>
>Toby Dunn
>
>
>
>
>
>From: jeli0703@HOTMAIL.CO.UK
>Reply-To: jeli0703@HOTMAIL.CO.UK
>To: SAS-L@LISTSERV.UGA.EDU
>Subject: Validating date date
>Date: Thu, 29 Jun 2006 08:38:43 -0700
>
>I have a large data set with a number of variables that have dates in
>it.
>
>Is there a way of checking that it is a valid date
>
>ie the data looks like
>
>Var1 var2 var3
>28/06/2006 . 32/01/2001
>28/06/2006 . 27/10/2007
>28/06/2006 27/10/2007 27/10/2007
>28/06/2006 27/10/2000 27/10/2007
>28/06/2006 27/10/2001 27/10/2007
>28/06/2006 27/10/2004 27/10/2007
>28/06/2006 27/10/2010 27/10/2007
>
>
>so basically i can do
>
>if missing (var2) then output a; which will identify missing dates
>thats fine
>
>what i need is something that will check that the remaining dates are
>correct is not 31/01/2001, dates in the future are ok as long as they
>would exist.