Discussion:
Time format with leading zero?
(too old to reply)
John Whittington
2008-12-29 20:26:18 UTC
Permalink
Hi folks,

Am I going mad or losing my memory? I surely must have encountered this a
million times before!

Is there not a format (available in v8.2) which produces what I would have
thought was the most commonly required format for a time variable,
namely HH:MM with HH padded with a leading zero if necessary - i.e. 07:59,
rather than 7:59 (which is what time5. appears to produce)? There are
obviously workarounds one could implement, but I just find it hard to
believe that such an intrinsic format does not exist!

TIA.

Kindest Regards,

John

----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: ***@mediscience.co.uk
Buckingham MK18 4EL, UK
----------------------------------------------------------------
Nordlund, Dan (DSHS/RDA)
2008-12-29 20:52:53 UTC
Permalink
-----Original Message-----
Behalf Of John Whittington
Sent: Monday, December 29, 2008 12:26 PM
Subject: Time format with leading zero?
Hi folks,
Am I going mad or losing my memory? I surely must have
encountered this a
million times before!
Is there not a format (available in v8.2) which produces what
I would have
thought was the most commonly required format for a time variable,
namely HH:MM with HH padded with a leading zero if necessary
- i.e. 07:59,
rather than 7:59 (which is what time5. appears to produce)? There are
obviously workarounds one could implement, but I just find it hard to
believe that such an intrinsic format does not exist!
TIA.
Kindest Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Buckingham MK18 4EL, UK
----------------------------------------------------------------
John,

In SAS 9 there is the TODw.d format which will do what you want, tod5. I don't know if it is in SAS 8.

Hope this is helpful,

Dan

Daniel J. Nordlund
Washington State Department of Social and Health Services
Planning, Performance, and Accountability
Research and Data Analysis Division
Olympia, WA 98504-5204
Arthur Tabachneck
2008-12-29 21:50:57 UTC
Permalink
John,

Try TOD5.

Art
-------
On Mon, 29 Dec 2008 20:26:18 +0000, John Whittington
Post by John Whittington
Hi folks,
Am I going mad or losing my memory? I surely must have encountered this a
million times before!
Is there not a format (available in v8.2) which produces what I would have
thought was the most commonly required format for a time variable,
namely HH:MM with HH padded with a leading zero if necessary - i.e.
07:59,
Post by John Whittington
rather than 7:59 (which is what time5. appears to produce)? There are
obviously workarounds one could implement, but I just find it hard to
believe that such an intrinsic format does not exist!
TIA.
Kindest Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Buckingham MK18 4EL, UK
----------------------------------------------------------------
John Whittington
2008-12-29 22:59:26 UTC
Permalink
Post by Arthur Tabachneck
John,
Try TOD5.
Many thanks, Art - 'just what the doctor ordered'!

Kind Regards,


John

----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: ***@mediscience.co.uk
Buckingham MK18 4EL, UK
----------------------------------------------------------------
John Whittington
2008-12-29 22:58:33 UTC
Permalink
Post by Nordlund, Dan (DSHS/RDA)
John,
In SAS 9 there is the TODw.d format which will do what you want, tod5. I
don't know if it is in SAS 8.
Hope this is helpful,
Thanks Dan. Yet, it is in SAS 8.2.

Kind Regards,


John

----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: ***@mediscience.co.uk
Buckingham MK18 4EL, UK
----------------------------------------------------------------
Ian Whitlock
2008-12-30 00:26:35 UTC
Permalink
Summary: Picture time format.
#iw-value=1

John,

You wanted a time format with leading 0's.

The TOD format has been suggested, but it works with DATETIME values
not TIME values. If your variable is time then you may have to roll
your own format.

1 proc format ;
2 picture ztime low-high = '%0H:%0M' (datatype=time) ;
NOTE: Format ZTIME has been output.
3 picture z12time low-high = '%0I:%0M' (datatype=time);
NOTE: Format Z12TIME has been output.
4 run ;

NOTE: PROCEDURE FORMAT used (Total process time):
real time 0.07 seconds
cpu time 0.01 seconds


5
6 data _null_ ;
7 input t time5. ;
8 put (3*t) (:8. :ztime5. :z12time5.) ;
9 cards ;

18180 05:03 05:03
55380 15:23 03:23

Ian Whitlock
PS: It has been a long time. Glad your back.
John Whittington
2008-12-30 01:06:26 UTC
Permalink
<html>
At 19:26 29/12/2008 -0500, Ian Whitlock wrote:<br>
<blockquote type=cite class=cite cite>John,<br><br>
You wanted a time format with leading 0's.<br><br>
The TOD format has been suggested, but it works with DATETIME
values<br>
not TIME values.&nbsp; If your variable is time then you may have to
roll<br>
your own format.</blockquote><br>
Ian, that's what I thought, but when two people suggested TOD, I thought
I ought to try it - and it appears to work fine (with TIME, as well as
DATETIME, values):<br><br>
<font face="SAS Monospace" size=1>21036&nbsp; data _null_ ;<br>
21037&nbsp;&nbsp;&nbsp;&nbsp; mytime = '07:59't ;<br>
21038&nbsp;&nbsp;&nbsp;&nbsp; put &quot;mytime = &quot; mytime tod5.
;<br>
21039&nbsp; run ;<br><br>
mytime = 07:59<br><br>
</font>I wonder if there are some risks in doing this (i.e. situations in
which it doesn't work as desired)?<br><br>
<blockquote type=cite class=cite cite>PS: It has been a long time.&nbsp;
Glad your back.</blockquote><br>
Thanks.&nbsp; It's good to be in contract with you again, too.&nbsp; I've
never actually been 'away', in terms of reading SAS-L, but life has been
so hectic for longer than I care to remember that I've had little time to
actually contribute.&nbsp; My occasional appearances these days tend to
be when I need help, rather than am offering it - which is a bit
parasitic, but I live in hope of the fact that there will soon be more
than 24 hours in a day, such that I'll be able to be a bit more
conspicuous and contributive again!<br><br>
Kind Regards,<br><br>
<br>
<div>John</div>
<br>
<div>----------------------------------------------------------------</div>
<div>Dr John Whittington,&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Voice:&nbsp;&nbsp;&nbsp; +44 (0) 1296 730225</div>
<div>Mediscience Services&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Fax:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; +44 (0) 1296 738893</div>
<div>Twyford Manor, Twyford,&nbsp;&nbsp;&nbsp; E-mail:&nbsp;&nbsp;
***@mediscience.co.uk</div>
<div>Buckingham&nbsp; MK18 4EL,
UK&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
</div>
----------------------------------------------------------------
</html>
Jack Hamilton
2008-12-30 03:21:43 UTC
Permalink
<http://support.sas.com/onlinedoc/913/docMainpage.jsp> says:

SAS time value

is a value representing the number of seconds since midnight
of the current day. SAS time values are between 0 and 86400.

SAS datetime value

is a value representing the number of seconds between
January 1, 1960 and an hour/minute/second within a specified
date.

So datetime values for January 1, 1960 will be in the same range as
time values for 00:00:00 to 24:00:00. As long as your values are in
that range, you'll be OK.

If you have a value greater than 24 hours, though, and you want to
display it in hours:minutes:seconds (or hours:minutes), you're out of
luck with TOD:

=====
1 data _null_;
2 t = '23:59:59't;
3 t2 = t + 100;
4 put t=tod5. t2=tod5.;
5 run;

t=23:59 t2=00:01
======



--
Jack Hamilton
***@alumni.stanford.org
Videtis illam spirare libertatis auram
Post by John Whittington
Post by Ian Whitlock
John,
You wanted a time format with leading 0's.
The TOD format has been suggested, but it works with DATETIME values
not TIME values. If your variable is time then you may have to roll
your own format.
Ian, that's what I thought, but when two people suggested TOD, I
thought I ought to try it - and it appears to work fine (with TIME,
21036 data _null_ ;
21037 mytime = '07:59't ;
21038 put "mytime = " mytime tod5. ;
21039 run ;
mytime = 07:59
I wonder if there are some risks in doing this (i.e. situations in
which it doesn't work as desired)?
Post by Ian Whitlock
PS: It has been a long time. Glad your back.
Thanks. It's good to be in contract with you again, too. I've
never actually been 'away', in terms of reading SAS-L, but life has
been so hectic for longer than I care to remember that I've had
little time to actually contribute. My occasional appearances these
days tend to be when I need help, rather than am offering it - which
is a bit parasitic, but I live in hope of the fact that there will
soon be more than 24 hours in a day, such that I'll be able to be a
bit more conspicuous and contributive again!
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Buckingham MK18 4EL, UK
----------------------------------------------------------------
unknown
2008-12-30 04:02:30 UTC
Permalink
Post by Jack Hamilton
SAS time value
is a value representing the number of seconds since midnight
of the current day. SAS time values are between 0 and 86400.
Interesting. Why the "current" day? It could be any day, possibly one not
indicated. It could be not specific to a particular day (eg, answer to the
question "what time do you usually awaken?"). Why the limit of 86,400? A
time value may report a duration rather than a time of day (eg, answer to
the question "how long will it take you to get from your home to the SAS
Global Forum?").
Post by Jack Hamilton
SAS datetime value
is a value representing the number of seconds between
January 1, 1960 and an hour/minute/second within a specified
date.
So datetime values for January 1, 1960 will be in the same range as
time values for 00:00:00 to 24:00:00. As long as your values are in
that range, you'll be OK.
If you have a value greater than 24 hours, though, and you want to
display it in hours:minutes:seconds (or hours:minutes), you're out of
=====
1 data _null_;
2 t = '23:59:59't;
3 t2 = t + 100;
4 put t=tod5. t2=tod5.;
5 run;
t=23:59 t2=00:01
======
--
Jack Hamilton
Videtis illam spirare libertatis auram
Post by John Whittington
Post by Ian Whitlock
John,
You wanted a time format with leading 0's.
The TOD format has been suggested, but it works with DATETIME values
not TIME values. If your variable is time then you may have to roll
your own format.
Ian, that's what I thought, but when two people suggested TOD, I
thought I ought to try it - and it appears to work fine (with TIME,
21036 data _null_ ;
21037 mytime = '07:59't ;
21038 put "mytime = " mytime tod5. ;
21039 run ;
mytime = 07:59
I wonder if there are some risks in doing this (i.e. situations in
which it doesn't work as desired)?
Post by Ian Whitlock
PS: It has been a long time. Glad your back.
Thanks. It's good to be in contract with you again, too. I've
never actually been 'away', in terms of reading SAS-L, but life has
been so hectic for longer than I care to remember that I've had
little time to actually contribute. My occasional appearances these
days tend to be when I need help, rather than am offering it - which
is a bit parasitic, but I live in hope of the fact that there will
soon be more than 24 hours in a day, such that I'll be able to be a
bit more conspicuous and contributive again!
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Buckingham MK18 4EL, UK
----------------------------------------------------------------
Jack Hamilton
2008-12-30 04:31:47 UTC
Permalink
Post by unknown
Interesting. Why the "current" day? It could be any day, possibly
one not
indicated.
Correct. I suspect it was easier to write that way. Perhaps the
editors felt that a simple "value representing the number of seconds
since midnight", without mentioning days, lacked a certain je ne sais
quoi.
Post by unknown
It could be not specific to a particular day (eg, answer to the
question "what time do you usually awaken?"). Why the limit of
86,400? A
time value may report a duration rather than a time of day (eg,
answer to
the question "how long will it take you to get from your home to the
SAS
Global Forum?").
It's probably worth mentioning somewhere that TOD. prints a time
modulo 24 hours, and time. prints the complete time.

=====
1 data _null_;
2 t = 200000;
3 put t=tod5. t=time.;
4 run;

t=07:33 t=55:33:20
=====


--
Jack Hamilton
***@alumni.stanford.org
Videtis illam spirare libertatis auram
Post by unknown
Post by Jack Hamilton
SAS time value
is a value representing the number of seconds since midnight
of the current day. SAS time values are between 0 and 86400.
Interesting. Why the "current" day? It could be any day, possibly
one not
indicated. It could be not specific to a particular day (eg, answer
to the
question "what time do you usually awaken?"). Why the limit of
86,400? A
time value may report a duration rather than a time of day (eg,
answer to
the question "how long will it take you to get from your home to the
SAS
Global Forum?").
Post by Jack Hamilton
SAS datetime value
is a value representing the number of seconds between
January 1, 1960 and an hour/minute/second within a specified
date.
So datetime values for January 1, 1960 will be in the same range as
time values for 00:00:00 to 24:00:00. As long as your values are in
that range, you'll be OK.
If you have a value greater than 24 hours, though, and you want to
display it in hours:minutes:seconds (or hours:minutes), you're out of
=====
1 data _null_;
2 t = '23:59:59't;
3 t2 = t + 100;
4 put t=tod5. t2=tod5.;
5 run;
t=23:59 t2=00:01
======
--
Jack Hamilton
Videtis illam spirare libertatis auram
Post by John Whittington
Post by Ian Whitlock
John,
You wanted a time format with leading 0's.
The TOD format has been suggested, but it works with DATETIME
values
not TIME values. If your variable is time then you may have to
roll
your own format.
Ian, that's what I thought, but when two people suggested TOD, I
thought I ought to try it - and it appears to work fine (with TIME,
21036 data _null_ ;
21037 mytime = '07:59't ;
21038 put "mytime = " mytime tod5. ;
21039 run ;
mytime = 07:59
I wonder if there are some risks in doing this (i.e. situations in
which it doesn't work as desired)?
Post by Ian Whitlock
PS: It has been a long time. Glad your back.
Thanks. It's good to be in contract with you again, too. I've
never actually been 'away', in terms of reading SAS-L, but life has
been so hectic for longer than I care to remember that I've had
little time to actually contribute. My occasional appearances these
days tend to be when I need help, rather than am offering it - which
is a bit parasitic, but I live in hope of the fact that there will
soon be more than 24 hours in a day, such that I'll be able to be a
bit more conspicuous and contributive again!
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Buckingham MK18 4EL, UK
----------------------------------------------------------------
Don Henderson
2008-12-30 04:58:42 UTC
Permalink
But one must be careful about the width used for the time format as
demonstrated by:

1 data _null_;
2 dt = datetime();
3 days = date();
4 hours = days*24;
5 t = time();
6 put days=best8. hours=best8. dt=time18. dt=time. t=time18.;
7 run;

days=17895 hours=429480 dt=429503:54:33 dt=429503 t=23:54:33

Note how the dt value displayed using the time18. format shows an hours
value of 429503 which is the number of days * 24 + 23. But if one uses the
default width for the time format is shows only the "most significant
digits" which in this case it determines to be the number of hours. I doubt
that many folks would see a datetime or time value displayed that way and
realize it was the number of hours.

Regards,
donh
-----Original Message-----
Behalf Of Jack Hamilton
Sent: Monday, December 29, 2008 11:32 PM
Subject: Re: Time format with leading zero?
Post by unknown
Interesting. Why the "current" day? It could be any day,
possibly one
Post by unknown
not indicated.
Correct. I suspect it was easier to write that way. Perhaps
the editors felt that a simple "value representing the number
of seconds since midnight", without mentioning days, lacked a
certain je ne sais quoi.
Post by unknown
It could be not specific to a particular day (eg, answer to the
question "what time do you usually awaken?"). Why the limit
of 86,400?
Post by unknown
A time value may report a duration rather than a time of day (eg,
answer to the question "how long will it take you to get from your
home to the SAS Global Forum?").
It's probably worth mentioning somewhere that TOD. prints a
time modulo 24 hours, and time. prints the complete time.
=====
1 data _null_;
2 t = 200000;
3 put t=tod5. t=time.;
4 run;
t=07:33 t=55:33:20
=====
--
Jack Hamilton
Videtis illam spirare libertatis auram
Post by unknown
On Mon, 29 Dec 2008 19:21:43 -0800, Jack Hamilton
Post by Jack Hamilton
SAS time value
is a value representing the number of seconds since midnight
of the current day. SAS time values are between 0 and 86400.
Interesting. Why the "current" day? It could be any day,
possibly one
Post by unknown
not indicated. It could be not specific to a particular day (eg,
answer to the question "what time do you usually awaken?"). Why the
limit of 86,400? A time value may report a duration rather
than a time
Post by unknown
of day (eg, answer to the question "how long will it take
you to get
Post by unknown
from your home to the SAS Global Forum?").
Post by Jack Hamilton
SAS datetime value
is a value representing the number of seconds between
January 1, 1960 and an hour/minute/second within a specified
date.
So datetime values for January 1, 1960 will be in the same
range as
Post by unknown
Post by Jack Hamilton
time values for 00:00:00 to 24:00:00. As long as your
values are in
Post by unknown
Post by Jack Hamilton
that range, you'll be OK.
If you have a value greater than 24 hours, though, and you want to
display it in hours:minutes:seconds (or hours:minutes),
you're out of
Post by unknown
Post by Jack Hamilton
=====
1 data _null_;
2 t = '23:59:59't;
3 t2 = t + 100;
4 put t=tod5. t2=tod5.;
5 run;
t=23:59 t2=00:01
======
--
Jack Hamilton
Videtis illam spirare libertatis auram
Post by John Whittington
Post by Ian Whitlock
John,
You wanted a time format with leading 0's.
The TOD format has been suggested, but it works with DATETIME
values not TIME values. If your variable is time then
you may have
Post by unknown
Post by Jack Hamilton
Post by John Whittington
Post by Ian Whitlock
to roll your own format.
Ian, that's what I thought, but when two people suggested TOD, I
thought I ought to try it - and it appears to work fine
(with TIME,
Post by unknown
Post by Jack Hamilton
Post by John Whittington
21036 data _null_ ;
21037 mytime = '07:59't ;
21038 put "mytime = " mytime tod5. ;
21039 run ;
mytime = 07:59
I wonder if there are some risks in doing this (i.e.
situations in
Post by unknown
Post by Jack Hamilton
Post by John Whittington
which it doesn't work as desired)?
Post by Ian Whitlock
PS: It has been a long time. Glad your back.
Thanks. It's good to be in contract with you again, too. I've
never actually been 'away', in terms of reading SAS-L,
but life has
Post by unknown
Post by Jack Hamilton
Post by John Whittington
been so hectic for longer than I care to remember that I've had
little time to actually contribute. My occasional
appearances these
Post by unknown
Post by Jack Hamilton
Post by John Whittington
days tend to be when I need help, rather than am offering
it - which
Post by unknown
Post by Jack Hamilton
Post by John Whittington
is a bit parasitic, but I live in hope of the fact that
there will
Post by unknown
Post by Jack Hamilton
Post by John Whittington
soon be more than 24 hours in a day, such that I'll be
able to be a
Post by unknown
Post by Jack Hamilton
Post by John Whittington
bit more conspicuous and contributive again!
Kind Regards,
John
----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Buckingham MK18 4EL, UK
----------------------------------------------------------------
John Whittington
2008-12-30 13:05:33 UTC
Permalink
Post by Jack Hamilton
So datetime values for January 1, 1960 will be in the same range as
time values for 00:00:00 to 24:00:00. As long as your values are in
that range, you'll be OK.
Right. That is my requirement. The data I have represents clocktime
within an (unspecified) day - so effectively the same as datetime values
for 01Jan1960.
Post by Jack Hamilton
If you have a value greater than 24 hours, though, and you want to
display it in hours:minutes:seconds (or hours:minutes), you're out of
Yes, I understand that, but it fortunately is not what I need.

I must say that I still am rather surprised that there is not an intrinsic
'Ztimew.d' format.

Kind Regards,


John

----------------------------------------------------------------
Dr John Whittington, Voice: +44 (0) 1296 730225
Mediscience Services Fax: +44 (0) 1296 738893
Twyford Manor, Twyford, E-mail: ***@mediscience.co.uk
Buckingham MK18 4EL, UK
----------------------------------------------------------------

Continue reading on narkive:
Loading...