Date: Mon, 19 Oct 2009 10:46:51 -0700
Reply-To: Sierra Information Services <sfbay0001@AOL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Sierra Information Services <sfbay0001@AOL.COM>
Organization: http://groups.google.com
Subject: Re: Proper SAS format for a difference in time XXXX
Content-Type: text/plain; charset=UTF-8
Hello...
My interpretation of the query is "how can I express the amount of
time elapsed between two events in days, hours minutes and seconds?"
Or, if I compute the number of seconds between the values of two
datetime variables, how can I then show the results as the number of
days, hours, minutes and seconds, rather than just the number of
seconds?
I poked around with this over the weekend and tried various
approaches. There does not seem to be a SAS format to do what needs
to be done here, and creating a customized Picture Format with the
DATATYPE=DATETIME option is not effective if the time between the two
events is one day or more, at least as far as I could tell.
So, I wrote a data step (below) that reports the number of days,
hours, minutes and seconds between to important historical events:
The datetime of the Apollo 11 liftoff and the datetime that Neil
Armstrong, the first man on the moon, said "That's one small step of
(a) man, one giant leap for mankind." I am hoping someone else can
contribute a more elegant approach to solving this problem, but here
is what I was able to do:
* compute and report the number of days, hours, minutes and seconds
from Apollo 11 liftoff to when Neil Armstrong said "That's one small
step
for a man, one giant leap for mankind" upon standing on the moon.
Timeline source: http://history.nasa.gov/SP-4029/Apollo_11i_Timeline.htm
Note: dates and times given in GMT;
options nodate nonumber nocenter;
data _null_;
file print;
title 'Elapsed Time Calculation';
title2 'Days, Hours, Minutes and Seconds from Apollo 11 Mission
Liftoff to When';
title3 "Neil Armstrong Said: 'That's One Small Step for a Man, One
Giant Leap for Mankind'";
title4 'While Standing on the Moon';
title5 'Timeline Source: http://history.nasa.gov/SP-4029/Apollo_11i_Timeline.htm';
title6 'Note: All Dates/Times Given in GMT';
retain secsinday 86400 secsinhour 3600 secsinmin 60 hoursinday 24;
liftoff = dhms('16jul1969'd,13,32,00); * lift off datetime;
onestep = dhms('21jul1969'd,02,56,15); * statement datetime;
total_seconds_elapsed = onestep - liftoff;
* numnber of full days (24 hr periods);
days = int(total_seconds_elapsed/secsinday);
* number of full hours remaining after substracting number of full
days;
hours = int(mod((total_seconds_elapsed/secsinday),1)*hoursinday) ;
* number of full minutes after subtracting number of full hours;
minutes = int(((mod((total_seconds_elapsed/secsinday),1)*hoursinday)
- hours)* secsinmin);
* number of seconds remaining after subtracting number of full
minutes,hours and days;
seconds = total_seconds_elapsed -
(days*secsinday) -
(hours*secsinhour) -
(minutes*secsinmin);
put / ;
put '*******************************************';
put "Apollo 11 Liftoff from Cape Kennedy:" +1 liftoff +1 "GMT";
put "Neil Armstrong Said: 'That's One Small Step for Man...':" +1
onestep +1 "GMT";
put +1 days 'Days' +1 hours 'Hours' +1 minutes "Minutes and" +1seconds
"Seconds After Liftoff";
format liftoff onestep datetime40.;
run;
Thanks for taking my thoughts in to consideration.
Andrew karp
Sierra Information Services
www.SierraInformation.com
On Oct 17, 5:00�pm, djnordl...@VERIZON.NET (Daniel Nordlund) wrote:
> > -----Original Message-----
> > From: SAS(r) Discussion [mailto:SA...@LISTSERV.UGA.EDU] On
> > Behalf Of Dan Abner
> > Sent: Saturday, October 17, 2009 4:48 PM
> > To: SA...@LISTSERV.UGA.EDU
> > Subject: Proper SAS format for a difference in time XXXX
>
> > Hi,
>
> > Can anyone suggest the best SAS format for a difference in time?
>
> > From what I can tell the TIMEw. & HHMMw. & MMSSw. are not
> > appropriate b/c
> > they report time from midnight. I just want to take the
> > number of seconds
> > between to time points and express it in hours, minutes, seconds as
> > appropriate.
>
> From one Dan to another :-), does this not do what you want?
>
> data have;
> � d1=datetime();
> � d2=dhms('15oct2009'd,0,0,0);
> � diff = d1-d2;
> � put diff=hhmm5.;
> run;
>
> Hope this is helpful,
>
> Dan
>
> Daniel Nordlund
> Bothell, WA USA- Hide quoted text -
>
> - Show quoted text -
|