<?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: Comparison with missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827129#M326705</link>
    <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;ELSE clause should not have executed for second row? My understanding is missing is unknown value and you can't compare it with any value like 1. When 1 &amp;lt; . or . &amp;lt;1, else should execute is my guess. Correct me if I'm wrong.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS only using BOOLEAN logic.&amp;nbsp; It does not use the TRI-level logic used by some other languages.&amp;nbsp; Any comparison will always result in either TRUE or FALSE.&amp;nbsp; Missing values are smaller than any actual number.&amp;nbsp; So . is less than 1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 04 Aug 2022 14:06:06 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-08-04T14:06:06Z</dc:date>
    <item>
      <title>Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827112#M326696</link>
      <description>&lt;P&gt;In the following code, can someone explain how I got 0 in first record and missing (.) in second record in the field&amp;nbsp;'Bias (Oversell Only)'n?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;data test_1;
input '1PD Lag'n 'Actual Shipments'n Material;
datalines;
. . 1234
. 1 123
1 . 12
;
run;

proc sql;
* Calculate Bias at the item level (to see if there is a demand planning issue nationally instead of just regionally);
create table work.bias_agg_1 as
select     MATERIAL,
        sum('1PD Lag'n) as '1PD Lag'n,
        sum('Actual Shipments'n) as 'Actual Shipments'n,
          case when sum('1PD Lag'n) &amp;lt; sum('Actual Shipments'n)
                  then (sum('1PD Lag'n) - sum('Actual Shipments'n)) / sum('Actual Shipments'n)
            else 0
           end as 'Bias (Oversell Only)'n
from     work.test_1
group by MATERIAL;
quit;
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="David_Billa_0-1659617695836.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74128i371E10B60A228487/image-size/medium?v=v2&amp;amp;px=400" role="button" title="David_Billa_0-1659617695836.png" alt="David_Billa_0-1659617695836.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 12:56:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827112#M326696</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-08-04T12:56:07Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827118#M326700</link>
      <description>&lt;P&gt;The second row is missing because you are doing a subtraction with a missing value, and the result is missing. The other rows are zero because the ELSE clause has executed.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 13:38:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827118#M326700</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-04T13:38:25Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827122#M326703</link>
      <description>&lt;P&gt;ELSE clause should not have executed for second row? My understanding is missing is unknown value and you can't compare it with any value like 1. When 1 &amp;lt; . or . &amp;lt;1, else should execute is my guess. Correct me if I'm wrong.&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 13:50:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827122#M326703</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-08-04T13:50:26Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827128#M326704</link>
      <description>&lt;P&gt;Missing is considered less than 1 (missing is considered less than any number), so the ELSE clause does not execute on row 2&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 14:04:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827128#M326704</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-08-04T14:04:17Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827129#M326705</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;ELSE clause should not have executed for second row? My understanding is missing is unknown value and you can't compare it with any value like 1. When 1 &amp;lt; . or . &amp;lt;1, else should execute is my guess. Correct me if I'm wrong.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS only using BOOLEAN logic.&amp;nbsp; It does not use the TRI-level logic used by some other languages.&amp;nbsp; Any comparison will always result in either TRUE or FALSE.&amp;nbsp; Missing values are smaller than any actual number.&amp;nbsp; So . is less than 1.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 14:06:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827129#M326705</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-04T14:06:06Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827132#M326706</link>
      <description>Aww, In general terms missing is unknown value and it can be any value and&lt;BR /&gt;it can be even greater than 1.&lt;BR /&gt;&lt;BR /&gt;Is it not the case in SAS?&lt;BR /&gt;</description>
      <pubDate>Thu, 04 Aug 2022 14:11:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827132#M326706</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2022-08-04T14:11:45Z</dc:date>
    </item>
    <item>
      <title>Re: Comparison with missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827136#M326709</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/292396"&gt;@David_Billa&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;Aww, In general terms missing is unknown value and it can be any value and&lt;BR /&gt;it can be even greater than 1.&lt;BR /&gt;&lt;BR /&gt;Is it not the case in SAS?&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;SAS has 28 distinct ways to store missing values.&amp;nbsp; The normal missing value (represented by a period) and 27 special missing values ( represented by .A to .Z and ._) . They will all be excluded when performing arithmetic.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But for comparisons SAS only uses BOOLEAN logic.&amp;nbsp; It does not support the TRI-level logic used by some other languages.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;They will all be treated by comparison operators as less than any actual number.&amp;nbsp;&amp;nbsp;I suspect that is probably a side effect of the specific codes they picked to represent those 28 missing values, but that is the way it has worked for almost 50 years.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can test if two values are using the same missing code or not with the equality operator.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do some testing:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  do x=-1 to 1, . , ._, .A , .Z ;
    output;
  end;
run;

proc sort data=test;
  by x;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Tom_0-1659623457936.png" style="width: 999px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/74133i2FDF6C815056F1F6/image-size/large?v=v2&amp;amp;px=999" role="button" title="Tom_0-1659623457936.png" alt="Tom_0-1659623457936.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 04 Aug 2022 14:31:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Comparison-with-missing-values/m-p/827136#M326709</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-08-04T14:31:09Z</dc:date>
    </item>
  </channel>
</rss>

