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 (May 2007, week 2)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Fri, 11 May 2007 16:50:51 -0400
Reply-To:     Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Peter Crawford <peter.crawford@BLUEYONDER.CO.UK>
Subject:      Re: Inputting Date/Time Values Stored As Text
Comments: To: Scott Barry <sbarry@SBBWORKS.COM>

On Fri, 11 May 2007 10:25:34 -0700, Scott Barry <sbarry@SBBWORKS.COM> wrote:

>On May 11, 12:21 pm, "Deborah Testa" <dte...@sevenofninesystems.com> >wrote: >> Hello, >> >> I am working with a data file that stored date/time values as text like >> this: >> >> 2005-08-01 17:52:33 >> >> Is there a quick way to get this into a datetime variable without >> parsing the two pieces? >> >> Thanks, >> >> Deborah > >In a DATA step, use the INPUT statement to read up the two fields >using the appropriate "date" and "time" INFORMAT, and then combine >them into a "datetime" variable using the DHMS function, substituting >the "time" variable as the Seconds argument of DHMS, and use "0" for >the Hour and Minute arguments. > >Scott Barry >SBBWorks, Inc.

Hi Scott

I've been using the SAS9 sashelp.vformat resource to search for correct informats.

The code data test ; set sashelp.vformat ; where fmttype='I' ; *just informats; where also fmtname ne:'$' ; * and not character informats;

string = '2005-08-01 17:52:33' ;

nd = inputn( string, fmtname, 27 ); if not _error_ ;

put fmtname= nd=best32. +1 nd datetime. +1 string=; option errors = 1; run;

The results show also that some date informats will return a non -missing value, but only these two achieve the correct timestamp.

extracted from the log

fmtname=ANYDTDTM nd=1438537953 01AUG05:17:52:33 string=2005-08-01 17:52:33 fmtname=YMDDTTM nd=1438537953 01AUG05:17:52:33 string=2005-08-01 17:52:33

Peter C


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