<?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: Unexpected rounding behavior in TIMEw.d format in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981423#M379119</link>
    <description>&lt;P&gt;Thanks for your input! I agree that the best practice is to use round() to control the decimal precision before applying a TIMEw.d format. I was mainly curious about the underlying logic and implementation details that lead to these edge-case behaviors.&lt;/P&gt;</description>
    <pubDate>Thu, 01 Jan 2026 16:35:30 GMT</pubDate>
    <dc:creator>ling0152</dc:creator>
    <dc:date>2026-01-01T16:35:30Z</dc:date>
    <item>
      <title>Unexpected rounding behavior in TIMEw.d format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981379#M379098</link>
      <description>&lt;P&gt;Hello everyone,&lt;/P&gt;&lt;P&gt;I’m encountering an unexpected rounding behavior when applying the TIME12.3 format to numeric values that share the same decimal part.&lt;/P&gt;&lt;P&gt;For example, consider the values 99.3765 and 67.3765. After applying TIME12.3, I obtain different results:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;P&gt;99.3765 → 0:01:39.377&lt;/P&gt;&lt;/LI&gt;&lt;LI&gt;&lt;P&gt;67.3765 → 0:01:07.376&lt;/P&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;This suggests that 99.3765 is being rounded up to .377, while 67.3765 is not.&lt;/P&gt;&lt;P&gt;Suspecting a floating-point representation issue, I examined their binary64 representations and converted them back to decimal. The results are:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For 99.3765&lt;BR /&gt;TIME12.3 result: 0:01:39.377&lt;BR /&gt;Binary64: 0100000001011000110110000001100010010011011101001011110001101010&lt;BR /&gt;Converted back: 99.37649999999999295142&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;For 67.3765&lt;BR /&gt;TIME12.3 result: 0:01:07.376&lt;BR /&gt;Binary64: 0100000001010000110110000001100010010011011101001011110001101010&lt;BR /&gt;Converted back: 67.37649999999999295142&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Both values are stored slightly below 0.3765, so based purely on their numeric representations, neither appears to meet the usual rounding threshold for .377. However, SAS rounds up 99.3765 but not 67.3765.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know why TIME12.3 would produce different rounding behavior for these two values? Could this be related to how SAS internally decomposes time values (for example, hours, minutes, seconds) or applies rounding during formatting?&lt;/P&gt;&lt;P&gt;For reference, here is the code I used:&lt;/P&gt;&lt;P&gt;data num;&lt;BR /&gt;input value;&lt;BR /&gt;datalines;&lt;BR /&gt;99.3765&lt;BR /&gt;67.3765&lt;BR /&gt;;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data time;&lt;BR /&gt;set num;&lt;BR /&gt;time = put(value, time12.3);&lt;BR /&gt;b64 = put(value, binary64.);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;Any insight into SAS’s internal rounding logic for time formats would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 02:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981379#M379098</guid>
      <dc:creator>ling0152</dc:creator>
      <dc:date>2025-12-31T02:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected rounding behavior in TIMEw.d format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981382#M379099</link>
      <description>&lt;P&gt;Interesting observation is that up to 100 minutes the rounding changes several times:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data num;
  do i=0 to 1e6;
    value=i+0.3765;
    output;
  end;
  format value 12.5;
run;

data time;
  set num;
  time = put(value, time12.3);

  r=scan(time,-1,"."); /* group by rounding */
run;

data time2;
  set time;
  by r notsorted;

  if first.r or last.r then output; /* get start and end of every group */
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Printout:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="yabwon_0-1767167112542.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/112459iFCD36007AA6ADB4D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="yabwon_0-1767167112542.png" alt="yabwon_0-1767167112542.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The higher number of seconds the "longer" the group.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 31 Dec 2025 07:46:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981382#M379099</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2025-12-31T07:46:12Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected rounding behavior in TIMEw.d format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981420#M379117</link>
      <description>&lt;P&gt;There a several places that decimal conversions can act oddly. If you see one then it may be that you should round to a desired decimal level before applying an inconsistent format.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jan 2026 14:35:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981420#M379117</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2026-01-01T14:35:48Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected rounding behavior in TIMEw.d format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981422#M379118</link>
      <description>&lt;P&gt;Hi Bart,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your input, this is a very interesting experiment. It appears that the flip points occur at powers of two and near minute/second boundaries (e.g., 120, 180, 240). It seems that the internal rounding behavior may be related to the binary64 representation of the data and how SAS handles minute/second carry-over internally.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jan 2026 16:30:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981422#M379118</guid>
      <dc:creator>ling0152</dc:creator>
      <dc:date>2026-01-01T16:30:06Z</dc:date>
    </item>
    <item>
      <title>Re: Unexpected rounding behavior in TIMEw.d format</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981423#M379119</link>
      <description>&lt;P&gt;Thanks for your input! I agree that the best practice is to use round() to control the decimal precision before applying a TIMEw.d format. I was mainly curious about the underlying logic and implementation details that lead to these edge-case behaviors.&lt;/P&gt;</description>
      <pubDate>Thu, 01 Jan 2026 16:35:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Unexpected-rounding-behavior-in-TIMEw-d-format/m-p/981423#M379119</guid>
      <dc:creator>ling0152</dc:creator>
      <dc:date>2026-01-01T16:35:30Z</dc:date>
    </item>
  </channel>
</rss>

