Date: Fri, 26 Aug 2005 16:30:14 +0100
Reply-To: "Crawford, Peter1" <peter1.crawford@CITIGROUP.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Crawford, Peter1" <peter1.crawford@CITIGROUP.COM>
Subject: Re: Cant read a Datetime using Datetime Format
Content-Type: text/plain; charset="UTF-8"
Dan
Do you think that if you use dsd, the embedded blank might be irrelevant.
And possibly the input modifier that accepts a single blank (as within an address line)
might suffice
as in these examples.......................
3664 data work.to_toby;
3665 infile cards dlm=',' dsd ;
3666 input toby_time ;
3667 put _infile_ $30. (_all_)(=);
3668 attrib toby_time informat= anydtdtm. format= datetime. ;
3669 cards;
10NOV2004 18:59:59 toby_time=10NOV04:18:59:59
10NOV2004 18:59:59.999 toby_time=10NOV04:19:00:00
8/26/5 13:50:21.12 toby_time=26AUG05:13:50:21
26-Aug-2005 13:38 toby_time=26AUG05:13:38:00
26/8/2005 13:49:25 toby_time=26AUG05:13:49:25
26/8/05 13:49:25 toby_time=05AUG26:13:49:25
NOTE: The data set WORK.TO_TOBY has 6 observations and 1 variables.
3676 ;
3677 data work.to_toby;
3678 *infile cards dlm=',' dsd ;
3679 input toby_time &;
3680 put _infile_ $30. (_all_)(=);
3681 attrib toby_time informat= anydtdtm. format= datetime. ;
3682 cards;
10NOV2004 18:59:59 toby_time=10NOV04:18:59:59
10NOV2004 18:59:59.999 toby_time=10NOV04:19:00:00
8/26/5 13:50:21.12 toby_time=26AUG05:13:50:21
26-Aug-2005 13:38 toby_time=26AUG05:13:38:00
26/8/2005 13:49:25 toby_time=26AUG05:13:49:25
26/8/05 13:49:25 toby_time=05AUG26:13:49:25
NOTE: The data set WORK.TO_TOBY has 6 observations and 1 variables.
-----Original Message-----
From: Daniel Nordlund [mailto:res90sx5@verizon.net]
Sent: 26 August 2005 16:23
To: Crawford, Peter1; SAS-L@LISTSERV.UGA.EDU
Subject: RE: Cant read a Datetime using Datetime Format
> -----Original Message-----
> From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of Peter
> Crawford
> Sent: Friday, August 26, 2005 6:00 AM
> To: SAS-L@LISTSERV.UGA.EDU
> Subject: Re: Cant read a Datetime using Datetime Format
>
> On Fri, 26 Aug 2005 01:45:49 -0700, RolandRB <rolandberry@HOTMAIL.COM>
> wrote:
>
> >tobyrathgeb@stanford.edu wrote:
> >> Hi
> >>
> >> I have a datetime in my raw (ASCII) file:
> >>
> >> 12/16/2004 9:10:31
> >>
> >> but cant read it with "datetime19." format in the input statement of my
> >> datastep. I saw that this format needs a 10NOV2004:18:59:59 layout of
> >> raw data, however "date." and "time." separately accept parts of my raw
> >> string. Can it be that this is again a limit in versatility of the sas
> >> language giving me the impression that it was developed without a
> >> systematic approach that usually guides a programming language.
> >>
> >> I appreciate your comments.
> >>
> >> Toby
> >
>
> Toby
>
> are you sure that should be 19. or 18. ?
> It's difficult to agree your comments without evidence.
>
> Perhaps the parsing of the data cell isn't as straightforward.
>
> Anyway, in sas9 try informat anydtdtm. For example:
>
> data to_toby;
> input toby_time ;
> put _infile $30. (_all_)(=);
> attrib toby_time informat= anydtdtm. format= datetime. ;
> cards;
> 10NOV2004:18:59:59
> 10NOV2004:18:59:59.999
> 8/26/5:13:50:21.12
> 26-Aug-2005:13:38
> 26/8/2005-13:49:25
> 26/8/05-13:49:25 toby_time=05AUG26:13:49:25
> ;
>
> On my system it seems to work, according to this log
>
> 1567 data to_toby;
> 1568 input toby_time;
> 1569 put _infile_ $30. (_all_)(=) ;
> 1570 attrib toby_time informat= anydtdtm. format= datetime. ;
> 1571 cards;
>
> 10NOV2004:18:59:59 toby_time=10NOV04:18:59:59
> 10NOV2004:18:59:59.999 toby_time=10NOV04:19:00:00
> 8/26/5:13:50:21.12 toby_time=26AUG05:13:50:21
> 26-Aug-2005:13:38 toby_time=26AUG05:13:38:00
> 26/8/2005-13:49:25 toby_time=26AUG05:13:49:25
> 26/8/05-13:49:25 toby_time=05AUG26:13:49:25
> NOTE: The data set WORK.TO_TOBY has 6 observations and 1 variables.
>
>
> If you don't like that last result, then remember to use y2k compliant
> years.
>
>
> Peter Crawford
>
> As I learn more of SAS, I also learn respect for how much
> of SAS I still don't know !
The example "datetime" that Toby gave has a blank in it, which is going to cause problems on input and will need to be worked around.
Dan Nordlund
Bothell, WA