<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Convert HHMM8. to Days in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68422#M14842</link>
    <description>&amp;gt; Hi,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I need to represent HHMM8. in days e.g. convert&lt;BR /&gt;
&amp;gt; 1958hrs and 56minutes to days i.e 40:12, what is the&lt;BR /&gt;
&amp;gt; best way to represent it FORMAT?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; When I tried to make a dataset like below, it reads&lt;BR /&gt;
&amp;gt; it as 32:39&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data test;&lt;BR /&gt;
&amp;gt;    FORMAT t1 HHMM8. ;&lt;BR /&gt;
&amp;gt; INPUT  t1  :stimer.;&lt;BR /&gt;
&amp;gt;  datalines;&lt;BR /&gt;
&amp;gt; 958:56&lt;BR /&gt;
&amp;gt; ;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What's wrong here?&lt;BR /&gt;
&lt;BR /&gt;
when you have a look at informat STIMER documentation ( &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a002295695.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a002295695.htm&lt;/A&gt; ) I think you will realise you chose the wrong informat!&lt;BR /&gt;
It appears to be the only built-in informat to accept that string, but treats a string with just one ':' as minutes:seconds (as I read the doc).&lt;BR /&gt;
There is a work-around which may or not work for you[pre]1784  data test;&lt;BR /&gt;
1785  FORMAT t1 HHMM8. ;&lt;BR /&gt;
1786  input dataline $char10. @1 @ ;&lt;BR /&gt;
1787  * add :00 as seconds, to the end of the infile buffer ;&lt;BR /&gt;
1788  substr( _infile_, length(_infile_)+1) = ':00' ;&lt;BR /&gt;
1789  INPUT t1 :stimer. ;&lt;BR /&gt;
1790  put t1=  dataline= ;&lt;BR /&gt;
1791  datalines;&lt;BR /&gt;
&lt;BR /&gt;
t1=1958:56 dataline=1958:56&lt;BR /&gt;
NOTE: The data set WORK.TEST[/pre]I added the dataline variable just for demonstration.&lt;BR /&gt;
 &lt;BR /&gt;
However, I don't see how that relates to 40 days and 12 hours?&lt;BR /&gt;
There isn't a built-in format for days and hours, but I can construct one[pre]1795  proc format ;&lt;BR /&gt;
1796   picture my_d_h(round) other = '%j:%H'( datatype=datetime) ;&lt;BR /&gt;
NOTE: Format MY_D_H has been output.&lt;BR /&gt;
1797  run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: PROCEDURE FORMAT used[/pre]This is OK for up to a year because the "%j" selects the number of days in the year, and your value T1 would hold a number of seconds. The kind of value in T1 can be treated as a datetime value. These start at the beginning of 1960. The datepart() of T1 is the number of days in the time/duration T1. We can use the %j directive for picture strings in PROC FORMAT (for a description of these directives, see: &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473467.htm#a000530223" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473467.htm#a000530223&lt;/A&gt; ) to get the number of days in your T1 duration - as long as it is less than or equal to the number of days in 1960!&lt;BR /&gt;
When I use my custom format it does not produce the answer you suggested 40:12[pre]1798  %put %sysfunc( inputn( 1958:56:0, stimer), my_d_h5 );&lt;BR /&gt;
82:14&lt;BR /&gt;
[/pre]That 80:14 is reasonable! &lt;BR /&gt;
 &lt;BR /&gt;
With 24 hours in a day, 40 days would be 960 hours and 80 days= 1920 hours, which is much closer to your 1958:56!&lt;BR /&gt;
 &lt;BR /&gt;
I look forward to some clarification!&lt;BR /&gt;
peterC</description>
    <pubDate>Thu, 03 Feb 2011 10:32:00 GMT</pubDate>
    <dc:creator>Peter_C</dc:creator>
    <dc:date>2011-02-03T10:32:00Z</dc:date>
    <item>
      <title>Convert HHMM8. to Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68420#M14840</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
I need to represent HHMM8. in days e.g. convert 1958hrs and 56minutes to days i.e 40:12, what is the best way to represent it FORMAT?&lt;BR /&gt;
&lt;BR /&gt;
When I tried to make a dataset like below, it reads it as 32:39&lt;BR /&gt;
&lt;BR /&gt;
data test;&lt;BR /&gt;
   FORMAT t1 HHMM8. ;&lt;BR /&gt;
   INPUT  t1  :stimer.;&lt;BR /&gt;
 datalines;&lt;BR /&gt;
1958:56&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
What's wrong here?</description>
      <pubDate>Thu, 03 Feb 2011 09:29:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68420#M14840</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-03T09:29:34Z</dc:date>
    </item>
    <item>
      <title>Re: Convert HHMM8. to Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68421#M14841</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
The stimer informats, whe a single colon is present, considers the value before as number of minutes and the value after number of seconds. so in your case, what you are actually reading with stimer informat is 1958minutes and 56seconds.&lt;BR /&gt;
&lt;BR /&gt;
TIME informat is better for your data.&lt;BR /&gt;
&lt;BR /&gt;
Marius</description>
      <pubDate>Thu, 03 Feb 2011 10:19:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68421#M14841</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-03T10:19:50Z</dc:date>
    </item>
    <item>
      <title>Re: Convert HHMM8. to Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68422#M14842</link>
      <description>&amp;gt; Hi,&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; I need to represent HHMM8. in days e.g. convert&lt;BR /&gt;
&amp;gt; 1958hrs and 56minutes to days i.e 40:12, what is the&lt;BR /&gt;
&amp;gt; best way to represent it FORMAT?&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; When I tried to make a dataset like below, it reads&lt;BR /&gt;
&amp;gt; it as 32:39&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; data test;&lt;BR /&gt;
&amp;gt;    FORMAT t1 HHMM8. ;&lt;BR /&gt;
&amp;gt; INPUT  t1  :stimer.;&lt;BR /&gt;
&amp;gt;  datalines;&lt;BR /&gt;
&amp;gt; 958:56&lt;BR /&gt;
&amp;gt; ;&lt;BR /&gt;
&amp;gt; run;&lt;BR /&gt;
&amp;gt; &lt;BR /&gt;
&amp;gt; What's wrong here?&lt;BR /&gt;
&lt;BR /&gt;
when you have a look at informat STIMER documentation ( &lt;A href="http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a002295695.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrdict/63026/HTML/default/viewer.htm#a002295695.htm&lt;/A&gt; ) I think you will realise you chose the wrong informat!&lt;BR /&gt;
It appears to be the only built-in informat to accept that string, but treats a string with just one ':' as minutes:seconds (as I read the doc).&lt;BR /&gt;
There is a work-around which may or not work for you[pre]1784  data test;&lt;BR /&gt;
1785  FORMAT t1 HHMM8. ;&lt;BR /&gt;
1786  input dataline $char10. @1 @ ;&lt;BR /&gt;
1787  * add :00 as seconds, to the end of the infile buffer ;&lt;BR /&gt;
1788  substr( _infile_, length(_infile_)+1) = ':00' ;&lt;BR /&gt;
1789  INPUT t1 :stimer. ;&lt;BR /&gt;
1790  put t1=  dataline= ;&lt;BR /&gt;
1791  datalines;&lt;BR /&gt;
&lt;BR /&gt;
t1=1958:56 dataline=1958:56&lt;BR /&gt;
NOTE: The data set WORK.TEST[/pre]I added the dataline variable just for demonstration.&lt;BR /&gt;
 &lt;BR /&gt;
However, I don't see how that relates to 40 days and 12 hours?&lt;BR /&gt;
There isn't a built-in format for days and hours, but I can construct one[pre]1795  proc format ;&lt;BR /&gt;
1796   picture my_d_h(round) other = '%j:%H'( datatype=datetime) ;&lt;BR /&gt;
NOTE: Format MY_D_H has been output.&lt;BR /&gt;
1797  run ;&lt;BR /&gt;
&lt;BR /&gt;
NOTE: PROCEDURE FORMAT used[/pre]This is OK for up to a year because the "%j" selects the number of days in the year, and your value T1 would hold a number of seconds. The kind of value in T1 can be treated as a datetime value. These start at the beginning of 1960. The datepart() of T1 is the number of days in the time/duration T1. We can use the %j directive for picture strings in PROC FORMAT (for a description of these directives, see: &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473467.htm#a000530223" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/a002473467.htm#a000530223&lt;/A&gt; ) to get the number of days in your T1 duration - as long as it is less than or equal to the number of days in 1960!&lt;BR /&gt;
When I use my custom format it does not produce the answer you suggested 40:12[pre]1798  %put %sysfunc( inputn( 1958:56:0, stimer), my_d_h5 );&lt;BR /&gt;
82:14&lt;BR /&gt;
[/pre]That 80:14 is reasonable! &lt;BR /&gt;
 &lt;BR /&gt;
With 24 hours in a day, 40 days would be 960 hours and 80 days= 1920 hours, which is much closer to your 1958:56!&lt;BR /&gt;
 &lt;BR /&gt;
I look forward to some clarification!&lt;BR /&gt;
peterC</description>
      <pubDate>Thu, 03 Feb 2011 10:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68422#M14842</guid>
      <dc:creator>Peter_C</dc:creator>
      <dc:date>2011-02-03T10:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: Convert HHMM8. to Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68423#M14843</link>
      <description>Hey thanks guys for such a quick response.&lt;BR /&gt;
&lt;BR /&gt;
1.&amp;gt; @Maurius- Indeed I forgot seconds&lt;BR /&gt;
&lt;BR /&gt;
2.&amp;gt; @Peter gr8 solution with Proc Format %j&lt;BR /&gt;
&lt;BR /&gt;
but I did this instead t1=input(t1,8.1)/86400, which gave me exactly 82.6</description>
      <pubDate>Thu, 03 Feb 2011 11:38:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68423#M14843</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-03T11:38:21Z</dc:date>
    </item>
    <item>
      <title>Re: Convert HHMM8. to Days</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68424#M14844</link>
      <description>and 40 was a typo I wanted to say 82.</description>
      <pubDate>Thu, 03 Feb 2011 14:01:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-HHMM8-to-Days/m-p/68424#M14844</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2011-02-03T14:01:06Z</dc:date>
    </item>
  </channel>
</rss>

