Date: Tue, 9 Mar 2004 16:42:49 -0500
Reply-To: Nathaniel_Wooding@DOM.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Nat Wooding <Nathaniel_Wooding@DOM.COM>
Subject: Re: Why DATEPART function is not working
Content-type: text/plain; charset=us-ascii
Anbu
To read the date starting with the name of the day, you will have to do
some string handling, at least in V8. I do not know if there is a suitable
format in v9.
I broke up the process into a bunch of intermediate steps for clarity; the
code could be written much more terseley with fewer variables.
Nat Wooding
data date;
longdate='Tue, Dec 2, 2003 ';
shortdate=scan(longdate,2,',');* extract the date that you want but note
that this needs to be 2 dec ;
month=scan(shortdate,1);
day=scan(shortdate,2);
yearpart=scan(longdate,3,',') ;
datepart=compbl(day||month||yearpart);* create the form 2 dec 2003;
date=input(datepart,date.);
format date mmddyy10.;
proc print;run;
Anbu
<aarumugam@STTHOM To: SAS-L@LISTSERV.UGA.EDU
AS.EDU> cc:
Sent by: "SAS(r) Subject: Re: Why DATEPART function is not working
Discussion"
<SAS-L@LISTSERV.U
GA.EDU>
03/09/01 05:10 PM
Please respond to
Anbu
Re: Why DATEPART function is not workingIt worked. Thanks. But if I have
value in worddate17 format like
Tue, Dec 2, 2003 How would I read. I tried many ways.
Help please.
Thanks
----- Original Message -----
From: Don & Susann
To: Anbu Arasu
Cc: SAS-L@LISTSERV.UGA.EDU
Sent: Sunday, March 07, 2004 1:41 AM
Subject: Re: Why DATEPART function is not working
Because X is not a datetime variable, it is a character string that has
the value
"'02DEC2003:00:00:00'dt"
That string literally is its value.
Its not clear from the example code what you are trying to do, but you
do not need to read the whole input datetime string if you only require
the datepart. Use
data dat ;
input @2 d date9. ;
put d= d= date9. ;
datalines;
02DEC2003:00:00:00
;
run;
Don
Anbu Arasu wrote:
> I tried extract datepart in the following program. But I could not. Why
> variable x is not equal to variable c.
> Thanks,
> Anbu
>
> data dat;
> input a $:20.;
> x= "'"||compress(a)||"'" || "dt";
> b=DATEPART('02DEC2003:00:00:00'dt);
> c='02DEC2003:00:00:00'dt;
> d=DATEPART(c);
> e=DATEPART(x);
> datalines;
> 02DEC2003:00:00:00
> ;
> run;
>
> proc print data=dat;
>
> run;
>
>
> output is
> a x b c d e
>
> 02DEC2003:00:00:00 '02DEC2003:00:00:00'dt 16041 1385942400 16041 .
>
>
--
Don Stanley, B.SC, Dip O.R.S, MNZCS
Author:: Beyond the obvious with SAS Screen Control Language.
Author:: Solutions for your GUI Applications Development Using SAS/AF
FRAME Technology
http://www.syswaregroup.com , http://homepages.rootsweb.com/~ashluke