<?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: question about comparison operators in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978524#M43560</link>
    <description>&lt;P&gt;You show some values with one decimal point displayed. What is the FORMAT currently assigned to the values? By default the displayed values are actually rounded by the format and so an actual value of 254.41 and 254.400338 would both display as 254.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this yields more of what you expect. The round function will round the values to the tenths decimal before the comparisons.&lt;/P&gt;
&lt;PRE&gt;data check1;
   set example;
   where round(hours1, 0.1)^= round(hours3,0.1) or round(hours2,0.1) ^= round(hours3,0.1);
   keep id hours1 hours2 hours3 ;
run;&lt;/PRE&gt;</description>
    <pubDate>Fri, 07 Nov 2025 18:26:27 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2025-11-07T18:26:27Z</dc:date>
    <item>
      <title>question about comparison operators</title>
      <link>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978519#M43557</link>
      <description>&lt;P&gt;&lt;SPAN&gt;Hi, &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I have a question about the NOT EQUAL operator and hope you can help. I want to compare the variable i created ("hours3") against the original data "hours1" and "hours2". Below is my code.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;data check1;&lt;BR /&gt;set example;&lt;BR /&gt;where hours1^=hours3 or hours2^=hours3;&lt;BR /&gt;keep id hours1 hours2 hours3 ;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;However, SAS ouput lots of observations that the three variables values are actually EQUAL.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;hours1&lt;/TD&gt;&lt;TD&gt;hours2&lt;/TD&gt;&lt;TD&gt;hours3&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;254.4&lt;/TD&gt;&lt;TD&gt;254.4&lt;/TD&gt;&lt;TD&gt;254.4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;243.2&lt;/TD&gt;&lt;TD&gt;243.2&lt;/TD&gt;&lt;TD&gt;243.2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;290.9&lt;/TD&gt;&lt;TD&gt;290.9&lt;/TD&gt;&lt;TD&gt;290.9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;291.9&lt;/TD&gt;&lt;TD&gt;291.9&lt;/TD&gt;&lt;TD&gt;291.9&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;TD&gt;202.2&lt;/TD&gt;&lt;TD&gt;202.2&lt;/TD&gt;&lt;TD&gt;202.2&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;SPAN&gt;I also made sure the format of three variables are the same but SAS still output values that are actually EQUAL. May I know what is the problem? Thanks!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 07 Nov 2025 17:49:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978519#M43557</guid>
      <dc:creator>sy2426</dc:creator>
      <dc:date>2025-11-07T17:49:48Z</dc:date>
    </item>
    <item>
      <title>Re: question about comparison operators</title>
      <link>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978524#M43560</link>
      <description>&lt;P&gt;You show some values with one decimal point displayed. What is the FORMAT currently assigned to the values? By default the displayed values are actually rounded by the format and so an actual value of 254.41 and 254.400338 would both display as 254.4.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;See if this yields more of what you expect. The round function will round the values to the tenths decimal before the comparisons.&lt;/P&gt;
&lt;PRE&gt;data check1;
   set example;
   where round(hours1, 0.1)^= round(hours3,0.1) or round(hours2,0.1) ^= round(hours3,0.1);
   keep id hours1 hours2 hours3 ;
run;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Nov 2025 18:26:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978524#M43560</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2025-11-07T18:26:27Z</dc:date>
    </item>
    <item>
      <title>Re: question about comparison operators</title>
      <link>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978526#M43562</link>
      <description>&lt;P&gt;Thanks so much ballardw! your solution using the round function worked.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My original variable hours and hours2 are in BEST12 (below).&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Alphabetic List of Variables and Attributes&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;#&lt;/TD&gt;&lt;TD&gt;Variable&lt;/TD&gt;&lt;TD&gt;Type&lt;/TD&gt;&lt;TD&gt;Len&lt;/TD&gt;&lt;TD&gt;Format&lt;/TD&gt;&lt;TD&gt;Informat&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;hours&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;BEST12.&lt;/TD&gt;&lt;TD&gt;BEST32.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;hours2&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;BEST12.&lt;/TD&gt;&lt;TD&gt;BEST32.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;id&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;BEST12.&lt;/TD&gt;&lt;TD&gt;BEST32.&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;hours3&lt;/TD&gt;&lt;TD&gt;Num&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;BEST12.&lt;/TD&gt;&lt;TD&gt;BEST12.&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 07 Nov 2025 18:39:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978526#M43562</guid>
      <dc:creator>sy2426</dc:creator>
      <dc:date>2025-11-07T18:39:13Z</dc:date>
    </item>
    <item>
      <title>Re: question about comparison operators</title>
      <link>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978532#M43567</link>
      <description>&lt;P&gt;This is a specific case of the general maxim:&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2012/06/25/programming-tip-avoid-testing-floating-point-values-for-equality.html" target="_self"&gt;Avoid testing floating-point values for equality&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;A more robust check for equality of floating-point numbers x and y is&lt;/P&gt;
&lt;P&gt;abs(x - x) &amp;lt; tol&lt;BR /&gt;where tol is a small number such as 1e-6.&lt;/P&gt;
&lt;P&gt;If testing floating-point numbers is something you do a lot, you could incorporate the logic into a macro, as follows:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* gernate some data where there are small difference betwen numbers */
data A;
call streaminit(12345);
do x1 = -5 to 5;
   x2 = x1 + rand("Normal",0,1e-6);
   x3 = x2 + rand("Normal",0,1e-6);
   output;
end;
run;

%macro FloatEq(a,b,tol=1e-6);
   (abs(&amp;amp;a - &amp;amp;b) &amp;lt; &amp;amp;tol)
%mend;

proc print data=A; 
where ^%FloatEq(x1,x3) OR ^%FloatEq(x2,x3);
format _all_ 12.9;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 07 Nov 2025 20:40:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/question-about-comparison-operators/m-p/978532#M43567</guid>
      <dc:creator>Rick_SAS</dc:creator>
      <dc:date>2025-11-07T20:40:12Z</dc:date>
    </item>
  </channel>
</rss>

