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 (July 2007, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 18 Jul 2007 09:42:29 -0400
Reply-To:     T J <tj_noreply@YAHOO.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         T J <tj_noreply@YAHOO.COM>
Subject:      Re: how to validate timestamps
Content-Type: text/plain; charset=ISO-8859-1

On Tue, 17 Jul 2007 18:26:54 -0400, Howard Schreier <hs AT dc-sug DOT org> <nospam@HOWLES.COM> wrote:

>On Tue, 17 Jul 2007 12:04:11 -0000, Peter <crawfordsoftware@GMAIL.COM> wrote: > >>On Jul 17, 12:31 pm, Rune Runnest� <r...@fastlane.no> wrote: >>> /* >>> The TIMESTAMP is when the data was saved in the database. >>> The format is: Year-month-day.clocktime >>> */ >>> data timestamps; >>> attrib timestamp length = $26.; >>> infile cards; >>> input @01 timestamp $26.; >>> datalines; >>> 1998-09-22-21.10.40.337502 >>> 1998-06-15-22.50.50.851490 >>> 1997-08-25-22.54.26.211287 >>> 1998-11-17-22.44.09.464875 >>> ; >>> run; >>> /* >>> How can I check that the values of TIMESTAMP are valid ? >>> >>> Regards, Rune >>> */ >> >>read it with a suitable informat, write it in your standard format, >>then compare it with original. > >Right. > >TIME informat will accept something like 10:90:00 as representing 11:30. So >just reading and checcking for non-missing time and date (or datetime) will >not catch everything.

As someone mentioned before, we need to compare the input string with the resulted date and time. Here is some code to re-construct a string from the imported date and time values and then compare it to original input.

HTH,

-TJ

data timestamps; input ts $26.;

dt = input(substr(ts, 1, 10), yymmdd10.); tm = input(substr(ts, 12 ), time16.) ; format dt yymmdd10. tm time16.6 ; tm_string=tranwrd(put(tm, time15.6), ':', '.'); result=put(dt, yymmdd10.)||'-'||tm_string ; if dt <= .Z or tm <= .Z then put 'WARNING: incorrect date or time, input= ' ts; else if tm > hms(24, 0, 0) then put 'WARNING: time-part is in question, input= ' ts; else if ts ne result then put "WARNING: Something is not right!" / " input=" ts / result= ; else OK='ok';

drop tm_string ; datalines; 1998-09-22-21.10.40.337502 1998-06-15-22.50.50.851490 1997-08-25-22.54.26.211287 1998-11-17-22.44.09.464875 1998-11-17-22.64.09.464875 1998-13-17-22.64.09.464875 1998-11-17-25.64.09.464875 ; run;

proc print; var ts result; run;

=====================

Obs ts result Ok

1 1998-09-22-21.10.40.337502 1998-09-22-21.10.40.337502 ok 2 1998-06-15-22.50.50.851490 1998-06-15-22.50.50.851490 ok 3 1997-08-25-22.54.26.211287 1997-08-25-22.54.26.211287 ok 4 1998-11-17-22.44.09.464875 1998-11-17-22.44.09.464875 ok 5 1998-11-17-22.64.09.464875 1998-11-17-23.04.09.464875 6 1998-13-17-22.64.09.464875 .-23.04.09.464875 7 1998-11-17-25.64.09.464875 1998-11-17-26.04.09.464875


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