From: rangoon rangoon on
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
From: Frank DiIorio on
On Mar 24, 9:48 am, rangoon rangoon <rangoonraja...(a)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);
From: data _null_; on
On Mar 24, 9:35 am, Frank DiIorio <frankdiio...(a)gmail.com> wrote:
> On Mar 24, 9:48 am, rangoon rangoon <rangoonraja...(a)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);- Hide quoted text -
>
> - Show quoted text -

You will want to use INPUT function with ID8601DT informat for
example.

data _null_;
input dtc :$30.;
dt = input(dtc,IS8601DT.);
put (dtc dt)(=);
format dt datetime20.;
datalines;
2008-01-12T00:00:00
;;
run;