| Date: | Sat, 30 Sep 2006 20:55:22 +0200 |
| Reply-To: | Rune Runnestø <rune@FASTLANE.NO> |
| Sender: | "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU> |
| From: | Rune Runnestø <rune@FASTLANE.NO> |
| Subject: | Validating date values in character variables |
|
*
Hi,
The dataset DATES contains valid and not valid date values, and the code in
the two
following data sets try to identify which ones are valid and which ones are
not.
The rules are:
1) '0000000000' is not a valid date value.
2) 01.02.02 is a valid date, even though we don't know whether it is 1902 or
2002.
3) The date must exist in the calender (f.ex, not 40.10.1998).
4) The value can be blank.
;
data dates;
attrib date_values length=$12.;
infile cards;
input @1 date_values $12.;
datalines;
0000000000
01.05.2001
31.12.2002
01.02.02
31.09.1999
40.10.1998
20.04.1800
22644840
01.01.21000
01.01.19900
01.01.19899
01.01.19999
01.01.20000
01.01.20100
;
run;
*The following data set seems to solve the problem OK, don't you think ?;
data not_valid1 (drop = datevalue)
is_valid1 (drop = datevalue)
;
set dates;
datevalue=input(compress(date_values,'.'), ddmmyy10.);
if date_values ne '' and datevalue = . then output not_valid1;
else output is_valid1;
run;
*But this one is not doing so well, as far as I can see from the output.
What is wrong with this ?;
data not_valid2
is_valid2
;
set dates;
if (date_values ne ' ' and date_values ne '0000000000') then do;
if missing(input(date_values,??yymmdd8.)) then output not_valid2;
end;
else output is_valid2;
run;
*Is there any other techniques to validate date values that are character
variables ?
Regards, Rune
;
|