<?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 in () affecting missing values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595208#M171188</link>
    <description>&lt;P&gt;Edited to make the example simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm seeing a difference in how SAS is handling missing values when evaluated alongside a condition using the in () operator.&amp;nbsp; The below code is really simplistic.&amp;nbsp; The only difference between data steps ___b and ___c is how y is evaluated in the if statement: y = 6 vs. y in (6).&amp;nbsp; However, the log shows the below missing NOTE for data step ___b, but not for data step ___c.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;1 at 10619:8&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What it is about adding a condition using the&amp;nbsp; in () operator that suddenly makes SAS try to resolve abs(x) whereas using = does not?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ___a;
    x = .; y = 5; output;
run;

data ___b;
    set ___a;

    if y in (6) and 
       abs(x) = 5;
run;

data ___c;
    set ___a;

    if y = 6 and
       abs(x) = 5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2019 14:46:20 GMT</pubDate>
    <dc:creator>Kastchei</dc:creator>
    <dc:date>2019-10-10T14:46:20Z</dc:date>
    <item>
      <title>in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595208#M171188</link>
      <description>&lt;P&gt;Edited to make the example simpler.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm seeing a difference in how SAS is handling missing values when evaluated alongside a condition using the in () operator.&amp;nbsp; The below code is really simplistic.&amp;nbsp; The only difference between data steps ___b and ___c is how y is evaluated in the if statement: y = 6 vs. y in (6).&amp;nbsp; However, the log shows the below missing NOTE for data step ___b, but not for data step ___c.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;BR /&gt;Each place is given by: (Number of times) at (Line):(Column).&lt;BR /&gt;1 at 10619:8&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What it is about adding a condition using the&amp;nbsp; in () operator that suddenly makes SAS try to resolve abs(x) whereas using = does not?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ___a;
    x = .; y = 5; output;
run;

data ___b;
    set ___a;

    if y in (6) and 
       abs(x) = 5;
run;

data ___c;
    set ___a;

    if y = 6 and
       abs(x) = 5;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 14:46:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595208#M171188</guid>
      <dc:creator>Kastchei</dc:creator>
      <dc:date>2019-10-10T14:46:20Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595226#M171195</link>
      <description>&lt;P&gt;Sas checks condition one by one.&lt;/P&gt;
&lt;P&gt;If y&amp;gt;5 then of course y is not in (1,2,3) so sas skips checking the next condition.&lt;/P&gt;
&lt;P&gt;When you mask the IN the sas have to check is abs(x) =5 and write the note.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 00:57:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595226#M171195</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-10-10T00:57:04Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595425#M171287</link>
      <description>&lt;P&gt;I'm not sure I'm following.&amp;nbsp; If SAS checks each condition one by one, then, in both ___b and ___c, SAS should stop checking after y &amp;gt; 5, meaning that in neither case should abs(.) be calculated.&amp;nbsp; However, it is being calculated in the uncommented version, but not in the commented version.&amp;nbsp; It's like the existence of the in () operator causes SAS to check all conditions even if the previous ones are already false.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I edited the original post to make the example simpler and the issue more clear.&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 14:47:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595425#M171287</guid>
      <dc:creator>Kastchei</dc:creator>
      <dc:date>2019-10-10T14:47:54Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595457#M171313</link>
      <description>&lt;P&gt;It seems that you are right&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;"&lt;STRONG&gt;&lt;SPAN&gt;the existence of the in () operator causes SAS to check all conditions even if the previous ones are already false."&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;it may be because when using &lt;STRONG&gt;in&amp;nbsp;&lt;/STRONG&gt;operator sas turns on a flag telling it to check all values in the () &lt;STRONG&gt;list&lt;/STRONG&gt;, but does not turn it off moving to&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;the next condition.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 15:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595457#M171313</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-10-10T15:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595461#M171316</link>
      <description>&lt;P&gt;That is surprising.&amp;nbsp; Unfortunately, SAS rules for short-circuiting (or not) are not well defined/documented.&amp;nbsp; This blog post discusses it, and has some links.&amp;nbsp;&amp;nbsp;&lt;A href="https://blogs.sas.com/content/iml/2019/08/14/short-circuit-evaluation-and-logical-ligatures-in-sas.html" target="_blank"&gt;https://blogs.sas.com/content/iml/2019/08/14/short-circuit-evaluation-and-logical-ligatures-in-sas.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 15:53:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595461#M171316</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-10-10T15:53:01Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595470#M171321</link>
      <description>&lt;P&gt;Looks like SAS has not implemented building short circuit logic into the code generated when the condition uses the IN operator.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Remember that IN could refer to an array of variables rather than a simple list of constant values, so the compiler would need to know the difference between:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x in (1,2,3)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;and&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x in array_name&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;It needs to know that since for the first it could hard code the numbers at compile time, but would need to generate code to check the values of the variables in the array at execution time for the second example since they could change.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It is also probably more work to understand&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x in (1,2,3)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;than a simple single value comparison:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x = 6&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2019 16:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595470#M171321</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-10-10T16:16:14Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595567#M171363</link>
      <description>&lt;P&gt;1&lt;EM&gt;.&amp;gt;but would need to generate code to check the values of the variables in the array at execution time for the second example&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;I would be disappointed if the compiler did not translate&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if VAL in ARR&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;to&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;if VAL=ARR[1] or VAL=ARR[2]&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;but it seems that it doesn't.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data ___b;           * realtime=2.5 seconds, no shortcut ;
  set ___a;
  do i=1 to 1e7;
    if Y in(1, 2) &amp;amp; abs(X)=5 then;
  end; 
run;
       
data ___b;           * realtime=3 seconds, no shortcut;
  set ___a;
  array ARR [2] _temporary_ (1,2) ;
  do i=1 to 1e7;
    if Y in ARR &amp;amp; abs(X)=5 then;
  end;
run;

data ___b;           * realtime=1 second, shortcut used;
  set ___a;
  array ARR [2] _temporary_ (1,2) ;
  do i=1 to 1e7;
    if (Y=ARR[1] | Y=ARR[2]) &amp;amp; abs(X)=5 then;
  end;
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>Thu, 10 Oct 2019 21:10:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595567#M171363</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2019-10-10T21:10:51Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595672#M171414</link>
      <description>&lt;P&gt;Sadly, not even the most obvious FALSE conditions, i.e. a literal zero or numeric missing, trigger short-circuiting in an IF statement:&lt;/P&gt;
&lt;PRE&gt;538  data _null_;
539  set ___a;
540  if 0 and abs(x)=5;
541  run;

NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;/PRE&gt;
&lt;P&gt;(Similar example here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/If-statement-Short-circuiting-and-Lag-function/m-p/473832#M121635" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/If-statement-Short-circuiting-and-Lag-function/m-p/473832#M121635&lt;/A&gt;)&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 09:24:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595672#M171414</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-11T09:24:04Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595730#M171449</link>
      <description>&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;Sadly, not even the most obvious FALSE conditions, i.e. a literal zero or numeric missing, trigger short-circuiting in an IF statement:&lt;/P&gt;
&lt;PRE&gt;538  data _null_;
539  set ___a;
540  if 0 and abs(x)=5;
541  run;

NOTE: Missing values were generated as a result of performing an operation on missing values.&lt;/PRE&gt;
&lt;P&gt;(Similar example here:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/If-statement-Short-circuiting-and-Lag-function/m-p/473832#M121635" target="_blank" rel="noopener"&gt;https://communities.sas.com/t5/SAS-Programming/If-statement-Short-circuiting-and-Lag-function/m-p/473832#M121635&lt;/A&gt;)&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Funny that IF 0 will not shortcut but IF 0=1 will shortcut:&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;25   data ___c;
26       set ___a;
27
28       if 0=1 and
29          abs(x) = 5;
30   run;

NOTE: There were 1 observations read from the data set WORK.___A.
NOTE: The data set WORK.___C has 0 observations and 2 variables.
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 13:47:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595730#M171449</guid>
      <dc:creator>Quentin</dc:creator>
      <dc:date>2019-10-11T13:47:33Z</dc:date>
    </item>
    <item>
      <title>Re: in () affecting missing values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595827#M171485</link>
      <description>&lt;P&gt;Thanks everyone for the information.&amp;nbsp; I didn't realize short-circuiting had a term, so I've learned a bit.&amp;nbsp; I appreciate it.&amp;nbsp; It looks like the summary is simply that SAS has not set up short-circuiting for use with the in() operator at this time.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2019 17:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/in-affecting-missing-values/m-p/595827#M171485</guid>
      <dc:creator>Kastchei</dc:creator>
      <dc:date>2019-10-11T17:12:00Z</dc:date>
    </item>
  </channel>
</rss>

