<?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: I meet with a problem of data values in do loops in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690863#M210196</link>
    <description>Really helpful solutions! Thank you!</description>
    <pubDate>Mon, 12 Oct 2020 00:27:10 GMT</pubDate>
    <dc:creator>Hong-tian</dc:creator>
    <dc:date>2020-10-12T00:27:10Z</dc:date>
    <item>
      <title>I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690795#M210178</link>
      <description>&lt;P&gt;Hi All, I generate a dataset named tmp1 using the following do loops, based on which I wanted to generate another dataset named tmp2. Although it is obvious that tmp2 would have one record, it did not.&lt;/P&gt;&lt;P&gt;Could anyone tell me what's wrong? Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;data tmp1;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&lt;U&gt;do i=0.025 to 0.250 by 0.025;&lt;/U&gt;&lt;BR /&gt;&lt;U&gt;output;&lt;/U&gt;&lt;BR /&gt;&lt;U&gt;end;&lt;/U&gt;&lt;BR /&gt;&lt;U&gt;run;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;data tmp2;&lt;/U&gt;&lt;BR /&gt;&lt;U&gt;set tmp1;&lt;/U&gt;&lt;BR /&gt;&lt;U&gt;if i eq 0.2;&lt;/U&gt;&lt;BR /&gt;&lt;U&gt;run;&lt;/U&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 15:45:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690795#M210178</guid>
      <dc:creator>Hong-tian</dc:creator>
      <dc:date>2020-10-11T15:45:45Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690796#M210179</link>
      <description>&lt;P&gt;This is a problem of &lt;A href="https://en.wikipedia.org/wiki/Machine_epsilon" target="_self"&gt;machine precision&lt;/A&gt;, where digital computers cannot represent some numbers exactly, and so the value in the data set is the number you expect within plus or minus some very small value epsilon.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, you can handle it this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp2;
    set tmp1;
    if fuzz(i-0.2)=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or this way&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp2;
set tmp1;
i=round(i,0.001);
if i eq 0.2;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 16:03:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690796#M210179</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2020-10-11T16:03:59Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690809#M210183</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;is right. Looping around floating points is a headache in many other programming languages as well. An easy fix would be to loop around integers, maintaining the same logic:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp1;
    do i=1 to 10 by 1; /*just multiple all numbers by 40 to keep it nice and simple*/
        i_=i/40; /*preserve value of i you originally wanted*/
        output;
    end;
run;

data tmp2;
    set tmp1;
    if i eq 0.2*40;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 11 Oct 2020 18:04:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690809#M210183</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-11T18:04:07Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690841#M210195</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351702"&gt;@vellad&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;is right. Looping around floating points is a headache in many other programming languages as well. An easy fix would be to loop around integers, maintaining the same logic:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp1;
    do i=1 to 10 by 1; /*just multiple all numbers by 40 to keep it nice and simple*/
        i_=i/40; /*preserve value of i you originally wanted*/
        output;
    end;
run;

data tmp2;
    set tmp1;
    if i eq 0.2*40;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Just to gild the lily: Converting to integer works, but more generally you just need to convert such that both the starting value and the increment are representable as powers of 2 (including non-positive powers representing 1, 1/2, 1/4, 1/8, etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So converting as below would work as well.&amp;nbsp; Any further change to integer would be no more than&amp;nbsp;floating the radix point - i.e. modifying the binary exponent.&amp;nbsp; Of course, it's not necessarily any more intuitive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data tmp1;
    do i=0.25 to 2.5 by 0.25; 
        i_=i/10; 
        output;
    end;
run;

data tmp2;
    set tmp1;
    if i eq 0.2*10;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 11 Oct 2020 23:11:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690841#M210195</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-10-11T23:11:38Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690863#M210196</link>
      <description>Really helpful solutions! Thank you!</description>
      <pubDate>Mon, 12 Oct 2020 00:27:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690863#M210196</guid>
      <dc:creator>Hong-tian</dc:creator>
      <dc:date>2020-10-12T00:27:10Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690864#M210197</link>
      <description>&lt;P&gt;I agree and will try to use intergers in do loops in my future works. Thank you!&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 00:28:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690864#M210197</guid>
      <dc:creator>Hong-tian</dc:creator>
      <dc:date>2020-10-12T00:28:58Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690865#M210198</link>
      <description>&lt;P&gt;Thank you for your further explanations. That's very helpful, in particular to the understanding of this problem.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 00:32:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690865#M210198</guid>
      <dc:creator>Hong-tian</dc:creator>
      <dc:date>2020-10-12T00:32:06Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690867#M210199</link>
      <description>Its neat. For Neo, definitely more intuitive &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt;</description>
      <pubDate>Mon, 12 Oct 2020 00:45:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690867#M210199</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-12T00:45:55Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690922#M210219</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/351702"&gt;@vellad&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I like the approach of using an integer index variable and use it regularly in similar situations. However, I would not use a selection criterion like&amp;nbsp;&lt;FONT face="courier new,courier"&gt;i eq 0.2*40&lt;/FONT&gt; where a calculation involves an operand (&lt;FONT face="courier new,courier"&gt;0.2&lt;/FONT&gt;) which is known to contain numeric representation error (although it works in this particular example). I would be much more confident that a calculation involving only integer operands of moderate size (like &lt;FONT face="courier new,courier"&gt;i_=i/40&lt;/FONT&gt; in your case) yields a result which can be safely used in comparisons (such as &lt;FONT face="courier new,courier"&gt;i_ eq 0.2&lt;/FONT&gt;). Of course, the safest option is to avoid decimal fractions altogether (as in &lt;FONT face="courier new,courier"&gt;i eq 8&lt;/FONT&gt;).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Warning example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
do i=1 to 99;
  x=i/100;
  a=(x=input(cats('0.',put(i,z2.)),8.)); /* testing e.g. x=0.07 */
  b=(i=x*100); /* testing e.g. i=0.07*100 */
  if ~a | ~b then output;
end;
run;

proc print data=test;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result (Windows SAS 9.4):&lt;/P&gt;
&lt;PRE&gt;Obs     i      x     a    b

 1      7    0.07    1    0
 2     14    0.14    1    0
 3     28    0.28    1    0
 4     29    0.29    1    0
 5     55    0.55    1    0
 6     56    0.56    1    0
 7     57    0.57    1    0
 8     58    0.58    1    0&lt;/PRE&gt;
&lt;P&gt;That is, e.g., the Boolean expression&amp;nbsp;&lt;FONT face="courier new,courier"&gt;7/100=0.07 &amp;amp; 0.07*100~=7&lt;/FONT&gt; is &lt;EM&gt;true&lt;/EM&gt; in SAS under Windows.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 10:13:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/690922#M210219</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-12T10:13:33Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691016#M210270</link>
      <description>&lt;P&gt;Hmm do you know why i and y don't match in below code?&amp;nbsp;I feel I'm missing something fundamental here.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="vellad_0-1602521411559.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/50563iD05A22A6A822163D/image-size/medium?v=v2&amp;amp;px=400" role="button" title="vellad_0-1602521411559.png" alt="vellad_0-1602521411559.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 17:00:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691016#M210270</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-12T17:00:19Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691020#M210272</link>
      <description>&lt;P&gt;My assertion was:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/32733"&gt;@FreelanceReinh&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;(...) the Boolean expression&amp;nbsp;&lt;FONT face="courier new,courier"&gt;7/100=0.07 &amp;amp; 0.07*100~=7&lt;/FONT&gt; is &lt;EM&gt;true&lt;/EM&gt; in SAS under Windows.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Your code first computes &lt;FONT face="courier new,courier"&gt;7/100&lt;/FONT&gt;&amp;nbsp;and rounds the result to two decimals, which doesn't change anything (as mentioned in my previous post), so &lt;FONT face="courier new,courier"&gt;x=0.07&lt;/FONT&gt;, and then the result of &lt;FONT face="courier new,courier"&gt;x*100&lt;/FONT&gt; -- a number close to, but not equal to 7 in SAS under Windows -- is stored in variable &lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt;. This, in turn, is compared to variable &lt;FONT face="courier new,courier"&gt;i&lt;/FONT&gt;, which contains the exact value 7. The IF condition is met and the OUTPUT statement produces one observation in dataset &lt;FONT face="courier new,courier"&gt;test&lt;/FONT&gt;, thus confirming my assertion. The reason for the inequality is a rounding error occurring in the multiplication of 0.07 -- which has no exact internal binary representation (i.e., variable &lt;FONT face="courier new,courier"&gt;x&lt;/FONT&gt; already contains a rounding error, called &lt;EM&gt;numeric representation error&lt;/EM&gt;) -- with 100.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;U&gt;Edit:&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;The decimal fraction 0.07, converted to the binary system (and with some line breaks inserted), looks like this:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;0.0001000111101011100001
    01000111101011100001
    01000111101011100001
    ...&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The 20-binary-digit pattern "&lt;FONT face="courier new,courier"&gt;01000111101011100001&lt;/FONT&gt;" is repeated &lt;EM&gt;infinitely many times&lt;/EM&gt; ("periodic fraction").&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The internal 64-bit floating-point representation that SAS under Windows uses to store 0.07 in an 8-byte numeric variable is based on the above binary representation. However, only 52 of the 64 bits (rather than infinitely many) are available for the binary digits following the first "&lt;FONT face="courier new,courier"&gt;1&lt;/FONT&gt;". The remaining binary digits are rounded (in this particular example: rounded &lt;EM&gt;up&lt;/EM&gt;), as can be seen with the BINARY64. format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x=0.07;
put x binary64.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;001111111011&lt;STRONG&gt;000111101011100001&lt;EM&gt;&lt;FONT color="#3366FF"&gt;01000111101011100001&lt;/FONT&gt;&lt;/EM&gt;01000111101100&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks to the periodicity, we know that the last four bits, &lt;STRONG&gt;&lt;FONT face="courier new,courier"&gt;1100&lt;/FONT&gt;&lt;/STRONG&gt;, resulted from rounding &lt;FONT face="courier new,courier"&gt;1011100001...&lt;/FONT&gt; to &lt;FONT face="courier new,courier"&gt;&lt;STRONG&gt;1100&lt;/STRONG&gt;000000... &lt;/FONT&gt;Apart from this, the 52 "mantissa bits" (in bold face above) are copied from the periodic binary representation and we recognize the repeating 20-binary-digit pattern (highlighted in blue).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Unlike most decimal fractions, integers (of moderate size) have exact&amp;nbsp;64-bit floating-point binary representations, ending in many zeros without rounding. Let's have a look at these representations of 100 and 7:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
x=100; y=7;
put (x y)(=binary64./);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;x=010000000101&lt;STRONG&gt;&lt;FONT color="#008000"&gt;100100&lt;/FONT&gt;0000000000000000000000000000000000000000000000&lt;/STRONG&gt;
y=010000000001&lt;STRONG&gt;&lt;FONT color="#008000"&gt;11&lt;/FONT&gt;00000000000000000000000000000000000000000000000000&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The 52 mantissa bits reflect the digits after the first "1" of the binary representations of 100 and 7, which are 1&lt;FONT color="#008000"&gt;100100&lt;/FONT&gt; and 1&lt;FONT color="#008000"&gt;11&lt;/FONT&gt;, respectively, padded with trailing zeros.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, the multiplication &lt;FONT face="courier new,courier"&gt;0.07*100&lt;/FONT&gt; (using the binary floating-point representations) amounts to multiplying the two numbers below:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;1.&lt;STRONG&gt;000111101011100001&lt;EM&gt;&lt;FONT color="#3366FF"&gt;01000111101011100001&lt;/FONT&gt;&lt;/EM&gt;01000111101100&lt;/STRONG&gt; * 2**-4
1.&lt;STRONG&gt;&lt;FONT color="#008000"&gt;100100&lt;/FONT&gt;&lt;/STRONG&gt; * 2**6&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;It's not difficult to do this multiplication by hand. Up to the factor &lt;FONT face="courier new,courier"&gt;2**-4 * 2**6 = 2**2 = 4&lt;/FONT&gt;, the result can be obtained as the sum (of shifted binary numbers)&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;  1.0001111010111000010100011110101110000101000111101100
+ 0.10001111010111000010100011110101110000101000111101100
&lt;U&gt;+ 0.00010001111010111000010100011110101110000101000111101100&lt;/U&gt;
  1.11000000000000000000000000000000000000000000000000001100&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;The latter number has a mantissa of 56 bits, hence it must be rounded to 52 bits in order to fit into an 8-byte numeric variable. As a consequence, the sequence of the least significant bits, &lt;FONT face="courier new,courier"&gt;...&lt;FONT color="#FF0000"&gt;0&lt;/FONT&gt;1100&lt;/FONT&gt; is rounded up to &lt;FONT face="courier new,courier"&gt;...&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;(0000)&lt;/FONT&gt;. So, for SAS under Windows the result of the multiplication is&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;1.110000000000000000000000000000000000000000000000000&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; * 2**2&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;written in floating-point representation:&lt;/P&gt;
&lt;PRE&gt;&lt;FONT size="4"&gt;010000000001110000000000000000000000000000000000000000000000000&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;Indeed, this matches the result obtained with the BINARY64. format:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
y=0.07*100;
put y binary64.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So, the difference between the result stored in variable&amp;nbsp;&lt;FONT face="courier new,courier"&gt;y&lt;/FONT&gt; and the exact value 7 (see internal representation further above) is &lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt; * 2**-50 = 8.881784...E-16, as is confirmed by SAS:&lt;/P&gt;
&lt;PRE&gt;455  data _null_;
456  d=0.07*100-7;
457  put d;
458  run;

8.881784E-16&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Oct 2020 19:42:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691020#M210272</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-12T19:42:06Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691041#M210282</link>
      <description>&lt;P&gt;I can use (apart from a simple ROUND on 0.07*100 ) the TRUNC function to limit the size of 0.07*100 to &amp;lt;= 7 bytes and the result remains 7. But if I use 8 bytes (default), there's the classic precision error. I'm still trying to wrap my head around this because TRUNC(0.7*10 ) and TRUNC(0.007*1000 ) both yield exactly 7. Its just TRUNC(0.07*100 ) that has an issue.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 18:21:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691041#M210282</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-12T18:21:46Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691076#M210294</link>
      <description>&lt;P&gt;I've just extended my previous post to demonstrate how the result of 0.07*100 (deviating from 7) comes about. If you perform similar DATA steps and hand calculations for 0.7*10 and 0.007*1000, you'll see why there are no issues with these two cases. (I've checked only the first case, which is relatively easy.) Note that the similarities between the three pairs of &lt;EM&gt;decimal&lt;/EM&gt; factors considered here does &lt;EM&gt;not &lt;/EM&gt;translate to similarities in the &lt;EM&gt;binary&lt;/EM&gt; system, i.e., the patterns of 0s and 1s are very different. For example, the lengths of the periods in the periodic binary representations of 0.7 and 0.007 are 4 and 100, respectively, not 20 as in the case of 0.07.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Using the TRUNC function with a second argument 7 (or 6, 5, ...) you truncate the 8 (or 16, 24, ...) least significant bits of the internal representation. In the example of 0.07*100 these bits, of course, include the rounding error 1 * 2**-50 (the "red &lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;" in the 52nd mantissa bit), so you get rid of it. If the results do not contain rounding errors in the internal representation (which happens to be true for&amp;nbsp;0.7*10 and 0.007*1000), the TRUNC function doesn't change that. This explains your observations.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Oct 2020 20:29:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691076#M210294</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2020-10-12T20:29:20Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691140#M210314</link>
      <description>Wow, thanks so much for the detailed response! I got it now and it is indeed not that counter intuitive how 0.07 is different from 0.7 and 0.007, once you go down to the bit level.</description>
      <pubDate>Tue, 13 Oct 2020 05:35:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691140#M210314</guid>
      <dc:creator>vellad</dc:creator>
      <dc:date>2020-10-13T05:35:58Z</dc:date>
    </item>
    <item>
      <title>Re: I meet with a problem of data values in do loops</title>
      <link>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691711#M210574</link>
      <description>Thank you for your step-by-step illustration. It's really helpful. I had never thought it in this way.</description>
      <pubDate>Thu, 15 Oct 2020 01:06:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/I-meet-with-a-problem-of-data-values-in-do-loops/m-p/691711#M210574</guid>
      <dc:creator>Hong-tian</dc:creator>
      <dc:date>2020-10-15T01:06:21Z</dc:date>
    </item>
  </channel>
</rss>

