<?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: basic arithmetic result not logical in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260605#M50604</link>
    <description>&lt;P&gt;Numerical precision.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although reference is 9.4 it does apply to 9.2 as well&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 01 Apr 2016 04:38:01 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-04-01T04:38:01Z</dc:date>
    <item>
      <title>basic arithmetic result not logical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260603#M50602</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I just did a practice of array and happened to find that one arithmetic result is not logical.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;**** data preparation ;
data visits;
    infile datalines;
    input patid visdt0 visdt1 visdt2 visdt3 visdt4;
    datalines;
1001 0.1 1.1 2.1 3.1 4.1
1002 0.2 1.2 2.2 3.2 4.2
;
run;

**** foolproof dataset;
data work.checkvisits;
    set work.visits (keep=patid visdt0 visdt1 visdt2 visdt3 visdt4);
    array visdt(1:5) visdt0 visdt1 visdt2 visdt3 visdt4;
    do i=2 to 5;
        x = visdt(i) - visdt(i-1);
        if x gt 1 then do;
            * there should be no output since all differences;
            * should equal to 1 ;
            put visdt(i-1)= visdt(i)= x=;
            output;
        end;
    end;
    drop i x;
run;

**** print ;
proc print data=checkvisits;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the log:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;```log&lt;/P&gt;&lt;P&gt;visdt1=1.2 visdt2=2.2 x=1&lt;BR /&gt;NOTE: There were 2 observations read from the data set WORK.VISITS.&lt;BR /&gt;NOTE: The data set WORK.CHECKVISITS has 1 observations and 6 variables.&lt;BR /&gt;NOTE: DATA statement used (Total process time):&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; real time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cpu time&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0.00 seconds&lt;/P&gt;&lt;P&gt;```&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The environment is SAS 9.2 on Linux. Please advise, thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 04:16:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260603#M50602</guid>
      <dc:creator>MichaelChung</dc:creator>
      <dc:date>2016-04-01T04:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: basic arithmetic result not logical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260605#M50604</link>
      <description>&lt;P&gt;Numerical precision.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm" target="_blank"&gt;http://support.sas.com/documentation/cdl/en/lrcon/68089/HTML/default/viewer.htm#p0ji1unv6thm0dn1gp4t01a1u0g6.htm&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Although reference is 9.4 it does apply to 9.2 as well&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 04:38:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260605#M50604</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-04-01T04:38:01Z</dc:date>
    </item>
    <item>
      <title>Re: basic arithmetic result not logical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260613#M50605</link>
      <description>&lt;P&gt;Thanks so much Reeza, I adjusted a bit the program and found two remainings do not match the real value probably due to truncation in binary numbers.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;13         **** foolproof dataset;
14         data work.checkvisits;
15             set work.visits;
16             array visdt(1:5) visdt0 visdt1 visdt2 visdt3 visdt4;
17             do i=2 to 5;
18                 * the expeced result should be 0 ;
19                 x = visdt(i) - visdt(i-1) - 1;
20                 put visdt(i-1)= visdt(i)= x=;
21                 if x gt 0 then do;
22                     output;
23                 end;
24             end;
&amp;#12;The SAS System

25             drop i x;
26         run;

visdt0=0.1 visdt1=1.1 x=0
visdt1=1.1 visdt2=2.1 x=0
visdt2=2.1 visdt3=3.1 x=0
visdt3=3.1 visdt4=4.1 x=-4.44089E-16
visdt0=0.2 visdt1=1.2 x=0
visdt1=1.2 visdt2=2.2 x=2.220446E-16
visdt2=2.2 visdt3=3.2 x=0
visdt3=3.2 visdt4=4.2 x=0
NOTE: There were 2 observations read from the data set WORK.VISITS.
NOTE: The data set WORK.CHECKVISITS has 1 observations and 6 variables.
NOTE: DATA statement used (Total process time):
      real time           0.00 seconds
      cpu time            0.00 seconds&lt;/PRE&gt;</description>
      <pubDate>Fri, 01 Apr 2016 05:49:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260613#M50605</guid>
      <dc:creator>MichaelChung</dc:creator>
      <dc:date>2016-04-01T05:49:20Z</dc:date>
    </item>
    <item>
      <title>Re: basic arithmetic result not logical</title>
      <link>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260751#M50640</link>
      <description>&lt;P&gt;Those are the exact types of issues that arise with numerical precision for decimals. If you do something like&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x = round( visdt(i) - visdt(i-1), 0.00001) -1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;you may be happier.&lt;/P&gt;</description>
      <pubDate>Fri, 01 Apr 2016 15:02:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/basic-arithmetic-result-not-logical/m-p/260751#M50640</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-04-01T15:02:07Z</dc:date>
    </item>
  </channel>
</rss>

