<?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 time format to integer value in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478812#M123505</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91804"&gt;@Malathi13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;
&lt;P&gt;I think you are right, if I remove the format, I get it in numbers but I want to see if I can just replace colon with a period and get the value as it is. Instead of 10:12 replace colon with period. Maybe using 'compress' function I can do that, not sure.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot replace the colon with a period. You are still confusing the format with the value. The value is 612. You could create a mathematical formula in SAS to convert 612 to 10.12, I will leave that up to you to figure out how to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Jul 2018 20:13:41 GMT</pubDate>
    <dc:creator>PaigeMiller</dc:creator>
    <dc:date>2018-07-17T20:13:41Z</dc:date>
    <item>
      <title>Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478802#M123496</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I need some help in converting time to numeric value, well not numeric value but convert 00:10:00 to 10 or 00:10:12 to 10.12 in SAS.&lt;/P&gt;&lt;P&gt;I tried using substr first to get only 10:00 but it didn't work.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data dummy;&lt;/P&gt;&lt;P&gt;set test;&lt;/P&gt;&lt;P&gt;time=substr(time1, 3,5); /* To get only 10:00, starting from 3rd digit and get five digits*/&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I don't want to convert 00:10:00 as 600 which is the numeric value for 10 minutes. I want to take out the colons and just get the number.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 19:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478802#M123496</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2018-07-17T19:52:20Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478803#M123497</link>
      <description>&lt;P&gt;I think you have confused the format of a variable and the value of a variable, these are not the same. Even though you see 00:10:12, the underlying value is in seconds. If you want to change 00:10:12 to 10.12, I don't think you did the math properly, the underlying value is 60*10+12 (60 seconds times 10 minutes, plus another 12 seconds). If you want this in minutes, you divide 60*10+12 by 60, and that is not 10.12.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;&lt;SPAN&gt;I want to take out the colons and just get the number.&lt;/SPAN&gt;&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Remove the format.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format time;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Then you see the value 612. Which was the value all along, the format only changed the way it appeared, it did not change the value itself.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:11:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478803#M123497</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-17T20:11:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478808#M123501</link>
      <description>&lt;P&gt;Convert to a character using PUT()&lt;/P&gt;
&lt;P&gt;Use COMPRESS() to remove colon&lt;/P&gt;
&lt;P&gt;Use INPUT() to read back in as integer.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:06:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478808#M123501</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2018-07-17T20:06:51Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478810#M123503</link>
      <description>&lt;P&gt;If you truly have a time value to begin (and not a character string), the accurate conversion formula would be:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;minutes = timevalue / 60;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you have a time value of 612 that is formatted as 10:12, and you want a not-so-accurate conversion formula to something&amp;nbsp;like 10.12, you can use:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;minutes = int(timevalue/60) + 0.01 * mod(timevalue, 60);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:08:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478810#M123503</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-07-17T20:08:30Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478811#M123504</link>
      <description>&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;&lt;P&gt;I think you are right, if I remove the format, I get it in numbers but I want to see if I can just replace colon with a period and get the value as it is. Instead of 10:12 replace colon with period. Maybe using 'compress' function I can do that, not sure.&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:11:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478811#M123504</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2018-07-17T20:11:07Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478812#M123505</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91804"&gt;@Malathi13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hi PaigeMiller,&lt;/P&gt;
&lt;P&gt;I think you are right, if I remove the format, I get it in numbers but I want to see if I can just replace colon with a period and get the value as it is. Instead of 10:12 replace colon with period. Maybe using 'compress' function I can do that, not sure.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You cannot replace the colon with a period. You are still confusing the format with the value. The value is 612. You could create a mathematical formula in SAS to convert 612 to 10.12, I will leave that up to you to figure out how to do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478812#M123505</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-17T20:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478813#M123506</link>
      <description>&lt;P&gt;Hi Astounding,&lt;/P&gt;&lt;P&gt;Thank you so so much!! Perfect conversion, I got 10:12 as 10.12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;M&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:14:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478813#M123506</guid>
      <dc:creator>Malathi13</dc:creator>
      <dc:date>2018-07-17T20:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478815#M123507</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/91804"&gt;@Malathi13&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;BR /&gt;Thank you so so much!! Perfect conversion, I got 10:12 as 10.12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;And don't try to do any math with this value 10.12, because although it's a number, it's not really a number that can be added or subtracted, &lt;EM&gt;etc&lt;/EM&gt;.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Jul 2018 20:17:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/478815#M123507</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2018-07-17T20:17:53Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782621#M249508</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/4954"&gt;@Astounding&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am having the same issue as well. Tried below solution but could not make it to work for my case.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have only two variables, DOSE_DT_TIME and PT. Every PT is supposed to take 2 doses daily with 12 hours difference. Paige Miller helped to calculate the difference between every two doses per PT and the difference is perfect. So with the above two original variables I have two additional variables now: Difference between the two dates formatted as TIME and non-formatted as difference in SECONDS (i.e., 12:09:00 and 43740). I need a new variable to calculate the difference in hours as number (i.e., 12.09 as 12 hours and 9 minutes). Last column below is calculating wrong number of hours.&lt;/P&gt;&lt;P&gt;Any help will be greatly appreciated. Thank you so much.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;PT&lt;/TD&gt;&lt;TD&gt;DOSE_DT_TIME&lt;/TD&gt;&lt;TD&gt;DIFF_FRMTD&lt;/TD&gt;&lt;TD&gt;DIFF_IN_SEC&lt;/TD&gt;&lt;TD&gt;DIFF_IN_HRS&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10/1/2021 21:52&lt;/TD&gt;&lt;TD&gt;12:52:00&lt;/TD&gt;&lt;TD&gt;46320&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;10/2/2021 10:30&lt;/TD&gt;&lt;TD&gt;12:38:00&lt;/TD&gt;&lt;TD&gt;45480&lt;/TD&g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200&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;10/4/2021 8:00&lt;/TD&gt;&lt;TD&gt;12:00:00&lt;/TD&gt;&lt;TD&gt;43200&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;10/4/2021 20:00&lt;/TD&gt;&lt;TD&gt;12:00:00&lt;/TD&gt;&lt;TD&gt;43200&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Her is part of the code.&lt;/P&gt;&lt;P&gt;DIFF_IN_SEC = DOSE_DT_TIME- LAG(DOSE_DT_TIME);&lt;BR /&gt;DIFF_IN_HRS = INT(DIFF_IN_SEC /3600) + 0.01 * MOD(DIFF_IN_SEC , 60);&lt;/P&gt;</description>
      <pubDate>Sat, 27 Nov 2021 02:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782621#M249508</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-27T02:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782622#M249509</link>
      <description>&lt;P&gt;To convert seconds to hours just divide by the number of seconds in an hour.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  diff_hours = diff_in_sec / '01:00't ;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 27 Nov 2021 02:49:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782622#M249509</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-27T02:49:52Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782623#M249510</link>
      <description>Hi Tom,&lt;BR /&gt;I tried that as well already but for some reason it did not give me correct results, e.g., formatted difference 11:58 was displayed as 11.96 instead of 11.58.&lt;BR /&gt;Thanks&lt;BR /&gt;</description>
      <pubDate>Sat, 27 Nov 2021 02:56:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782623#M249510</guid>
      <dc:creator>SAS_USER_928</dc:creator>
      <dc:date>2021-11-27T02:56:46Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782625#M249511</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/407996"&gt;@SAS_USER_928&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Hi Tom,&lt;BR /&gt;I tried that as well already but for some reason it did not give me correct results, e.g., formatted difference 11:58 was displayed as 11.96 instead of 11.58.&lt;BR /&gt;Thanks&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It makes no sense to store 11.58 as a number.&amp;nbsp; 11 hours and 58/100ths of an hour is a totally different number than 11 hours and 58/60ths of an hour.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to make a character string with a period instead of a colon you could use the TRANSLATE() function to convert the colon to a period.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;hour_string = translate( put(time_value,tod5.) , '.' , ':' );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Or depending on your LOCALE setting you might be able to just use the NLTIME format.&amp;nbsp;&lt;A href="https://go.documentation.sas.com/doc/en/vdmmlcdc/8.1/leforinforref/p0ywh4fysyz7yyn1wl67rz6zogmt.htm" target="_blank"&gt;https://go.documentation.sas.com/doc/en/vdmmlcdc/8.1/leforinforref/p0ywh4fysyz7yyn1wl67rz6zogmt.htm&lt;/A&gt;&amp;nbsp;to display time using period instead of colon as the separator between the hours and minutes.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Nov 2021 06:44:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782625#M249511</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-11-27T06:44:16Z</dc:date>
    </item>
    <item>
      <title>Re: Convert time format to integer value</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782718#M249537</link>
      <description>&lt;P&gt;SAS contains a format to print the number of seconds as HHMM.&amp;nbsp; You don't need to calculate hours once you know the number of seconds.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;format diff_in_sec hhmm5. ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 28 Nov 2021 03:43:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Convert-time-format-to-integer-value/m-p/782718#M249537</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2021-11-28T03:43:39Z</dc:date>
    </item>
  </channel>
</rss>

