<?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: Data Structure and Algorithm of SAS in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762730#M30404</link>
    <description>Study this.  There will be a quiz in the morning.</description>
    <pubDate>Fri, 20 Aug 2021 02:04:05 GMT</pubDate>
    <dc:creator>mkeintz</dc:creator>
    <dc:date>2021-08-20T02:04:05Z</dc:date>
    <item>
      <title>Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762518#M30367</link>
      <description>&lt;P&gt;Hello There,&lt;/P&gt;&lt;P&gt;I'm a new user of SAS programming, and now I've some trouble related calculation values of SAS.&lt;/P&gt;&lt;P&gt;I use SAS Enterprise Guide to calculate some values and I discovered that it's unreasonable sometimes.&lt;/P&gt;&lt;P&gt;As an example, see below.&lt;/P&gt;&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D = Divide(FLOOR(B),FLOOR(C))&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sebestian_0-1629377115887.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62720i2E778245B97640EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sebestian_0-1629377115887.png" alt="Sebestian_0-1629377115887.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone has an answer or the way to solve this case, please describe or explain me.&lt;/P&gt;&lt;P&gt;I can't thank you enough for your help.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 13:05:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762518#M30367</guid>
      <dc:creator>Sebestian</dc:creator>
      <dc:date>2021-08-19T13:05:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762523#M30368</link>
      <description>&lt;P&gt;The value of either B or C (or both) is not an exact integer (even though it displays as an integer). B is less than C. Change the formatting of B and C to something like best32. to see what the true values are.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 13:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762523#M30368</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-08-19T13:15:11Z</dc:date>
    </item>
    <item>
      <title>Re: Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762532#M30369</link>
      <description>&lt;P&gt;Please show the log from the full code you ran.&lt;/P&gt;
&lt;P&gt;Please post data as text, not photographs.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 13:24:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762532#M30369</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-19T13:24:43Z</dc:date>
    </item>
    <item>
      <title>Re: Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762562#M30370</link>
      <description>&lt;P&gt;I think you need to use ROUND for what you intend.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;   D = Divide(round(B,1),round(C,1))&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393915"&gt;@Sebestian&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello There,&lt;/P&gt;
&lt;P&gt;I'm a new user of SAS programming, and now I've some trouble related calculation values of SAS.&lt;/P&gt;
&lt;P&gt;I use SAS Enterprise Guide to calculate some values and I discovered that it's unreasonable sometimes.&lt;/P&gt;
&lt;P&gt;As an example, see below.&lt;/P&gt;
&lt;P&gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; D = Divide(FLOOR(B),FLOOR(C))&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Sebestian_0-1629377115887.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/62720i2E778245B97640EE/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Sebestian_0-1629377115887.png" alt="Sebestian_0-1629377115887.png" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If anyone has an answer or the way to solve this case, please describe or explain me.&lt;/P&gt;
&lt;P&gt;I can't thank you enough for your help.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 15:01:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762562#M30370</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-08-19T15:01:21Z</dc:date>
    </item>
    <item>
      <title>Re: Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762574#M30371</link>
      <description>&lt;P&gt;Or try the FLOORZ function.&lt;/P&gt;
&lt;P&gt;If a value is very close to an integer , i.e. within 1E-12 or so, then the Floor function can actually round up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data example;
   x= 1.999999999999;
   y=floor(x);
   z=floorz(x);
run;&lt;/PRE&gt;
&lt;P&gt;Note that y is 2 and z is 1 in the result.&lt;/P&gt;
&lt;P&gt;So if your two variables are slightly off of the shown picture the results of Floor may be different than expected.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;63   data example;
64      z= 17687/17688;
65      put z= best32.;
66   run;

z=0.9999434644957
&lt;/PRE&gt;
&lt;P&gt;This Z value agrees with your result when rounded to 9 decimal places so is likely the actual values used in the division shown.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 15:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762574#M30371</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-19T15:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762592#M30376</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393915"&gt;@Sebestian&lt;/a&gt;&amp;nbsp;and welcome to the SAS Support Communities!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Looking at the result in variable &lt;FONT face="courier new,courier"&gt;d&lt;/FONT&gt; (knowing from the formula that it is a ratio of integers, both of which must be close to 17688), it is easy to guess and then to verify that&amp;nbsp;&lt;FONT face="courier new,courier"&gt;d=17687/17688&lt;/FONT&gt;. So, the question remains why &lt;FONT face="courier new,courier"&gt;floor(b)=17687&lt;/FONT&gt; while &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; is displayed as &lt;FONT face="courier new,courier"&gt;17688&lt;/FONT&gt; (most likely in a default format such as BEST12.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Of course, a small rounding error in a calculation might result in something like &lt;FONT face="courier new,courier"&gt;b=17687.99999...&lt;/FONT&gt;, but doesn't the &lt;A href="https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/lefunctionsref/p1xuvvu3to43jmn187gqlmpk3hi7.htm" target="_blank" rel="noopener"&gt;documentation of the FLOOR function&lt;/A&gt; reassure us that the result is "&lt;EM&gt;fuzzed to avoid unexpected floating-point results&lt;/EM&gt;"? In the "Details" section it says: "&lt;EM&gt;If the argument is within 1E-12 of an integer, the function returns that integer.&lt;/EM&gt;" What is the smallest possible rounding error that would diminish the exact result 17688? Let's look at the internal binary floating-point representation of 17688 (using SAS 9.4 under Windows)&lt;FONT face="helvetica"&gt;:&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;707  data _null_;
708  x=17688;
709  put x binary64. / x hex16.;
710  run;

010000001101000101000110000000000000000000000000000000000000000&lt;STRONG&gt;0&lt;/STRONG&gt;
40D1460000000000&lt;/PRE&gt;
&lt;P&gt;Since &lt;FONT face="courier new,courier"&gt;2**&lt;STRONG&gt;14&lt;/STRONG&gt; = 16384 &amp;lt;= 17688 &amp;lt; 32768 = 2**15&lt;/FONT&gt;, we know (from&amp;nbsp;&lt;A href="https://documentation.sas.com/?docsetId=lrcon&amp;amp;docsetTarget=p0ji1unv6thm0dn1gp4t01a1u0g6.htm&amp;amp;docsetVersion=9.4&amp;amp;locale=en" target="_blank" rel="noopener"&gt;Numerical Accuracy in SAS Software&lt;/A&gt;) that the place value of the least significant bit (highlighted above) is &lt;FONT face="courier new,courier"&gt;2**(&lt;STRONG&gt;14&lt;/STRONG&gt;-52) = 2**-38 ≈ 3.6E-12&lt;/FONT&gt;. So it's &lt;EM&gt;greater than 1E-12&lt;/EM&gt; and thus escaping the fuzzing algorithm. This means that already &lt;FONT face="courier new,courier"&gt;b=input('40D14&lt;U&gt;5FFFFFFFFFF&lt;/U&gt;',hex16.)&lt;/FONT&gt; -- the largest internal numeric value less than 17688 -- yields &lt;FONT face="courier new,courier"&gt;floor(b)=17687&lt;/FONT&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How can a result like&amp;nbsp;&lt;FONT face="courier new,courier"&gt;40D145FFFFFFFFFF&lt;/FONT&gt; (in HEX16. format) arise? Easily! As shown below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;812  data test;
813  x=37688.2;
814  y=20000.2;
815  b=x-y;
816  if b ne 17688 then put 'Surprised?';
817  f=floor(b);
818  r=round(b,1e-9);
819  diff=r-b;
820  put b=best32.-L / b=32.26 / b=hex16. / r=hex16. / f= / diff=;
821  run;

Surprised?
b=17688
b=17688.00000000000000000000000000
b=40D145FFFFFFFFFF
r=40D1460000000000
f=17687
diff=3.637979E-12&lt;/PRE&gt;
&lt;P&gt;Even the longest formats such as BEST32. conceal (due to rounding&lt;FONT face="helvetica"&gt;!&lt;/FONT&gt;) that &lt;FONT face="courier new,courier"&gt;b ne 17688&lt;/FONT&gt;, which is only revealed by special formats like HEX16. or by looking at the difference &lt;FONT face="courier new,courier"&gt;diff&lt;/FONT&gt;&amp;nbsp;(&lt;FONT face="courier new,courier"&gt;=2**-38&lt;/FONT&gt;). Rounding with a suitable rounding unit greater than &lt;FONT face="courier new,courier"&gt;diff&lt;/FONT&gt;&amp;nbsp;yields the desired result (see variable &lt;FONT face="courier new,courier"&gt;r&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The mathematically exact value stored in &lt;FONT face="courier new,courier"&gt;b&lt;/FONT&gt; in the above dataset &lt;FONT face="courier new,courier"&gt;test&lt;/FONT&gt;, i.e. &lt;FONT face="courier new,courier"&gt;17688-2**-38&lt;/FONT&gt;, is&lt;/P&gt;
&lt;PRE&gt;17687.99999999999636202119290828704833984375&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bottom line: &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;nailed it. B is not an exact integer.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 19 Aug 2021 16:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762592#M30376</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-08-19T16:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: Data Structure and Algorithm of SAS</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762730#M30404</link>
      <description>Study this.  There will be a quiz in the morning.</description>
      <pubDate>Fri, 20 Aug 2021 02:04:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Data-Structure-and-Algorithm-of-SAS/m-p/762730#M30404</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-08-20T02:04:05Z</dc:date>
    </item>
  </channel>
</rss>

