f



converting character datetime(ISO) to numeric datetime20.

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
3
rangoon
3/24/2010 1:48:19 PM
comp.soft-sys.sas 142827 articles. 4 followers. Post Follow

2 Replies
10027 Views

Similar Articles

[PageSpeed] 14

On Mar 24, 9:48=A0am, rangoon rangoon <rangoonraja...@gmail.com> wrote:
> Hi All,
> I have a character date =A0dtc(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;
> =A0 =A0 input dtc $ 30.;
> =A0 =A0 datalines;
> =A0 =A0 2008-01-12T00:00:00
> =A0 =A0 ;;
> run;
>
> data want;
> =A0 =A0 set have;
> =A0 =A0 format dtnum datetime20.;
> =A0 =A0dtd =3D input(substr(dtc,1,10),yymmdd10.);
> =A0 =A0dtm=3D input(scan(dtc,2,"T"),time8.);
> =A0 =A0dtnum =3D =A0dhms(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 =3D IS8601DT(dtc);
0
Frank
3/24/2010 2:35:42 PM
On Mar 24, 9:35=A0am, Frank DiIorio <frankdiio...@gmail.com> wrote:
> On Mar 24, 9:48=A0am, rangoon rangoon <rangoonraja...@gmail.com> wrote:
>
>
>
>
>
> > Hi All,
> > I have a character date =A0dtc(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;
> > =A0 =A0 input dtc $ 30.;
> > =A0 =A0 datalines;
> > =A0 =A0 2008-01-12T00:00:00
> > =A0 =A0 ;;
> > run;
>
> > data want;
> > =A0 =A0 set have;
> > =A0 =A0 format dtnum datetime20.;
> > =A0 =A0dtd =3D input(substr(dtc,1,10),yymmdd10.);
> > =A0 =A0dtm=3D input(scan(dtc,2,"T"),time8.);
> > =A0 =A0dtnum =3D =A0dhms(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;
> =A0 =A0 =A0set have;
> =A0 =A0 =A0dtNum =3D 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 =3D input(dtc,IS8601DT.);
   put (dtc dt)(=3D);
   format dt datetime20.;
   datalines;
2008-01-12T00:00:00
    ;;
run;
0
data
3/24/2010 4:58:37 PM
Reply:

Similar Artilces:

Convert ISO datetime to SAS datetime
Does anyone know if SAS has a function to convert ISO datetime values to SAS datetime values. Thanks! Jake ...

Re: Convert ISO datetime to SAS datetime
Jake A while back, someone pointed out some SAS informats that work with ISO datetimes but do ==>NOT<== appear in the base SAS informats. Rather, they are apparently in the XML libname docs. The list is: These formats and informats are available beginning in Release 8.2, specifically for the XML engine support: INFORMAT DESCRIPTION PATTERN IS8601DA date YYYY-MM-DD IS8601DN datetime with date portion YYYY-MM-DD IS8601DT datetime YYYY-MM-DDThh:mm:ss[.fffff] IS8601DZ ...

Re: Convert ISO datetime to SAS datetime #3
SAS doesn't have ISO datetime values. It has ISO datetime formats and informats, even if they are not documented in the correct place. A datetime value is stored as a SAS numeric value which is simply the number of seconds since midnight at the start of the epoch. If you have character data (either a character variable or text in a file) representing a date and time in an ISO format that you want to store in a datetime variable, you use the INPUT function or statement as appropriate and specify the relevant ISO informat. If you have a datetime value that you need to express in ISO styl...

Re: Convert ISO datetime to SAS datetime #2
For v9.2, it is not under Base: http://support.sas.com/documentation/cdl/en/lrdict/59540/HTML/default/a00316 9726.htm On Thu, 18 Sep 2008 14:46:59 -0400, Nat Wooding <Nathaniel.Wooding@DOM.COM> wrote: >Jake > >A while back, someone pointed out some SAS informats that work with ISO >datetimes but do ==>NOT<== appear in the base SAS informats. Rather, they >are apparently in the XML libname docs. > >The list is: > > > > > > >These formats and informats are available beginning in Release 8.2, >specifically for the XML engine support: &g...

Re: Convert ISO datetime to SAS datetime #4
Nat and Jake; Good news for users of SAS 9.2. The set of IS8601... formats and informats are aliases for the set of E8601... formats and informats, which are documented in the standard location for Base SAS 9.2. Ed Ed Heaton TB-286 #4818 -----Original Message----- From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Nat Wooding Sent: Thursday, September 18, 2008 2:47 PM To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Convert ISO datetime to SAS datetime Jake A while back, someone pointed out some SAS informats that work with ISO datetimes but do ==>NOT<== appear in the ...

SAS : How to convert character date to numeric date
Hi All, I am working with SAS language. I am in need of converting character date to numeric date. Eg. I have records with date in character form '2007/10/01', so now I need to convert this into 01OCT2007 (date9.) format. Can any one help me. On 31 Mar., 08:17, suhaskir...@gmail.com wrote: > Hi All, > > I am working with SAS language. I am in need of converting character > date to numeric date. > > Eg. I have records with date in character form '2007/10/01', so now I > need to convert this into 01OCT2007 (date9.) format. Can any one help > me. Here i...

Re: SAS : How to convert character date to numeric date
> -----Original Message----- > From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On > Behalf Of Bo Hovgaard Thomasen > Sent: Tuesday, March 31, 2009 1:10 AM > To: SAS-L@LISTSERV.UGA.EDU > Subject: Re: SAS : How to convert character date to numeric date > > On 31 Mar., 08:17, suhaskir...@gmail.com wrote: > > Hi All, > > > > I am working with SAS language. I am in need of converting character > > date to numeric date. > > > > Eg. I have records with date in character form > '2007/10/01', so now I > > need to conve...

Analyzing a SAS data Set and converting character to numeric
Here is the task: I have a SAS data set with ~1,400 variables. My goal is to look at observations in a column and if it is formatted as character but qualifies to be a numeric, then change the column to be formatted as numeric. I have tried to build a macro that does this, but each time I do, I end up converting columns that should have stayed as character to numeric and wipe out the data. I know I can simply export the file and import it using the wizard or proc import, but I need to add this functionality to a larger piece of code and only need to run it once in awhile. Any suggestions ...

Sas/Access to Oracle DB question (how to convert long numerics to character)
I was wondering if you could help me. I am trying to pull data from the Oracle tables the SAS access passthrough. The account numbers are stored in the oracle databases as numeric (19 digits) and so if you pull it down as normal (or using a libname), the last few digits lose precision. I tried the following and while the customer_id is character with 19 digits, it also loses precision (seems that the last 2-3 numbers are garbage/random). proc sql; connect to oracle as oradb (user=3Dxxxxx password=3D=92xxxxxxx' path=3D'dbname' ); create table dat.test as ...

Newbie, still :-(, SAS question convert numeric variable to character variable
I have been trying to find out how to convert a numeric field to a character field in an SQL procedure. example: proc sql; select distinct case when test2.newid NE "" then test2.newid else ('**' || substr(test1.idno,3,2)) end as n_idno from test1; quit; but test1.idno is a numeric variable Thanks, Richard On Mar 1, 12:02 pm, "DH" <sheehan...@yahoo.com> wrote: > I have been trying to find out how to convert a numeric field to a > character field in an SQL procedure. > > example: > proc sql; > select distinc...

Convert to numeric where Date field Numeric and Character
I have a date field can be numeric and populated or character and blank (only these 2 scenarios) if it's populated it has this format MMDDYY10. numeric and if it's character then it's just blank. so what i need is for the numeric date to look like this: Numeric, Length 8, Format 11. and look like 20100214 and if it's character then convert it so it looks like 20100214. Thank you ...

Convert numeric to Character BUT add or delete characters
i have a field "Orig" which is numeric BEST12. Length: 8 I need to convert it into character $7.0 by adding leading 0's or deleting last 2 zeros if the value is 9 characters long. Example: Orig New Field (should be) 53447 0053447 116556 116556 121749000 1217490 167757400 1677574 Thanks for the help. How about the following code? data a; input orig best12.; datalines; 53447 116556 121749000 167757400 ; run; data b; set a; if length(strip(orig)) <7 then newfield=put(orig, z7.); else if length(strip(or...

Re: Convert to numeric where Date field Numeric and Character
I presume this is a linked question to your other one. If this is an excel sheet and you want to force it to come in properly, then use DBSASOPTS or similar in the import/libname. If you have an already existing dataset, or just prefer to do it this way, you could create a new variable, format it numeric, and then set it equal to the other variable; it will always be numeric, and will be missing if the variable is formatted (and contains) characters. ie data want; set have; format newdatevar YYMMDDN8.; newdatevar = olddatevar; run; -Joe On Thu, Feb 18, 2010 at 11:48 AM, Sdlentertd <sd...

Convert Datetime data from ASCII code to SAS Datetime
Hello everyone, =20 I have a question regarding converting ASCII data_time into SAS format. For example, the format in ASCII file is: =20 2006-01-12 12:24 2006-01-12 12:25 .... , with 1-minute interval.=20 =20 I have now read it as Character in SAS dataset. Could anyone give me a hint as to the best way to convert it to SAS Datetime?=20 =20 Many thanks. =20 Julie ...