Date: Tue, 5 May 2009 11:02:02 -0700
Reply-To: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject: Re: Date Formats...
In-Reply-To: A<200905051742.n45GIO7R000894@malibu.cc.uga.edu>
Content-Type: text/plain; charset="us-ascii"
Hi Joe,
You've got some solutions already but
I will give you the why as well.
SAS uses the numeric variable to store
the number of days since 1/1/1960 or
the number of seconds since 1/1/1960.
SAS calls these date and datetime
respectively. Obviously, the difference
between one second and one day is that
one day contains 24hr * 60mins * 60secs.
Therefore 24*60*60 is a factor of 86400.
When you use the DATE9. format SAS expects
to deal with the number of days, and since
you are specifying DTDATE9. (the DT stands
for DATETIME) the dtdate9. format is dividing
your variable X by 86400 and then the result
is less than 1 and the format is displaying
day 0 regardless of the number of seconds
during day one, thus 1JAN1960 as in your
datastep below:
* yours ;
data want;
x=date();
y=date();
format x dtdate9. y ddmmyy10.;
put _all_;
run;
* should be for number of days ;
data want;
x=date();
y=date();
format x date9. y ddmmyy10.;
put _all_;
run;
* could be if you converted to datetime ;
* i.e. datetime being number of seconds ;
data want;
x=date()*86400;
y=date();
format x dtdate9. y ddmmyy10.;
put _all_;
run;
Hope this is helpful.
Mark Terjeson
Investment Business Intelligence
Investment Management & Research
Russell Investments
253-439-2367
Russell
Global Leaders in Multi-Manager Investing
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
SUBSCRIBE SAS-L Joe H. Smith
Sent: Tuesday, May 05, 2009 10:43 AM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Date Formats...
Hi all;
I have the following code here.....
data want;
x=date();
y=date();
format x dtdate9. y ddmmyy10.;
run;
MY O/P is ... x y
01Jan1960 05/05/2009
Can you explain me why there is a difference in date values,when i am
using the same date function for both the variables..only my format type
is changing,if i want x to have a value of 05May2009,How can i get
this .My desired output ...if i use the same formats as mentioned
above...
x y
05May2009 05/05/2009
Thanks in Adv.