SAS DateTime

280 views
Skip to first unread message

sukumarb...@gmail.com

unread,
Apr 15, 2008, 8:27:10 AM4/15/08
to MedStats
Hi All,
My Raw data file contains Date in (yyyy-mm-dd HH:MM:SS.ddd eg.,
2007-10-18 09:50:50.000) this format, please help me how to import
this in SAS.
Thanks in advance,
Regards,
Sukumar

BXC (Bendix Carstensen)

unread,
Apr 15, 2008, 9:52:33 AM4/15/08
to MedS...@googlegroups.com
Look in the sas manual under "informats" there are examples that
shows how to read this type of fields.

John Whittington

unread,
Apr 15, 2008, 9:55:57 AM4/15/08
to MedS...@googlegroups.com
At 05:27 15/04/2008 -0700, sukumarb...@gmail.com wrote:
>My Raw data file contains Date in (yyyy-mm-dd HH:MM:SS.ddd eg.,
>2007-10-18 09:50:50.000) this format, please help me how to import
>this in SAS. Thanks in advance, Regards, Sukumar

Sukumar, as you ahve presumably discovered, to the best of my knowledge SAS
does not have an informat corresponding to that Datetime format. I would
therefore suggest that you read the datetime value in as a character value
(length=23), extract the date and time parts from that character string as
SAS date and time variables, then combine the SAS date value with the
hours, minutes and seconds extracted from the SAS time variable to give you
a single SAS datetine variable containing the value from the raw data:

data test (drop = dtIn date1 time1) ;
input dtIn $23. ;
date1 = input(substr(dtIn,1,10), yymmdd10.) ;
time1 = input(substr(dtIn,12), time12.) ;
DateTime1 = dhms(date1,hour(time1),minute(time1),second(time1)) ;
cards ;
2007-10-18 09:50:50.000
2008-04-15 12:15:50.123
1975-06-21 15:12:12.345
;
run ;

proc print data=test noobs ;
format DateTime1 datetime20.3 ;
run ;;

I have used the datetime20.3 format to display the contents of the created
SAS datetime variable, but you could obviously use any format you
wished. The output of the above print procedure is:

DateTime1

18OCT07:09:50:50.000
15APR08:12:15:50.123
21JUN75:15:12:12.345

Does that acgieve what you want?

Kind Regards,


John

----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: Joh...@mediscience.co.uk
Buckingham MK18 4EL, UK
----------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages