Date: Wed, 24 Mar 2010 07:35:42 -0700
Reply-To: Frank DiIorio <frankdiiorio@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Frank DiIorio <frankdiiorio@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: converting character datetime(ISO) to numeric datetime20.
Content-Type: text/plain; charset=ISO-8859-1
On Mar 24, 9:48 am, rangoon rangoon <rangoonraja...@gmail.com> wrote:
> Hi All,
> I have a character date dtc(2008-01-12T00:00:00
> ) in data have. i want to create a new variable dtnum with datetime20.
> format as 12JAN2008:00:00:00.
>
> i am looking for a function or better way of doing then what i am
> doing now. in data want i create using three steps. is there a better
> way or does SAS provide a isodatetime function .
>
> data have;
> input dtc $ 30.;
> datalines;
> 2008-01-12T00:00:00
> ;;
> run;
>
> data want;
> set have;
> format dtnum datetime20.;
> dtd = input(substr(dtc,1,10),yymmdd10.);
> dtm= input(scan(dtc,2,"T"),time8.);
> dtnum = dhms(dtd,hour(dtm),minute(dtm),second(dtm));
> run;
>
> Thank you,
> Rang
The IS8601DT should work. From the documentation: "The IS8601DT
informat reads datetime values into a variable in the extended format
YYYY-MM-DDThh:mm:ss".
data want;
set have;
dtNum = IS8601DT(dtc);
|