Date: Mon, 19 Oct 2009 13:28:10 -0500
Reply-To: Joe Matise <snoopy369@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Joe Matise <snoopy369@GMAIL.COM>
Subject: Re: Proper SAS format for a difference in time XXXX
In-Reply-To: <fc21718c-eec9-4e03-a991-a63b55c4f808@x6g2000prc.googlegroups.com>
Content-Type: text/plain; charset=UTF-8
I don't quite interpret it that way. Specifically, the OP does not mention
days. There are plenty of applications where a duration longer than 24h
should be displayed in hours, not in days, after all.
I would think this would meet the specifications of the OP (of course, those
specifications could be inadequate):
data test;
format d time12.;
x=dhms('16jul1969'd,13,32,00);
y=dhms('21jul1969'd,02,56,15);
d=y-x;
put d=;
run;
Regardless, if you really wanted to display days, it seems to me a picture
format handles that fine, with the caveat that it's only valid up to one
year:
proc format lib=work;
picture dtsecs
/*0-2678400=%0d':'%0H':'%0M':'%0S (datatype=datetime) Only valid for
one month*/
0-3e7=%0j':'%0H':'%0M':'%0S (datatype=datetime) /* Valid for one year
*/
other='INVALID';
quit;
data test;
format d time12.;
x=dhms('16jul1969'd,13,32,00);
y=dhms('21jul1969'd,02,56,15);
d=y-x;
put d=;
format e dtsecs.;
e=d;
put e=;
e=9e6;
put e=;
e=9e7;
put e=;
run;
If you're looking at over a year, you're probably a bit nuts to want days
instead of years, anyhow. :)
-Joe
On Mon, Oct 19, 2009 at 12:46 PM, Sierra Information Services <
sfbay0001@aol.com> wrote:
> 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 -
>
|