<?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: output does not match code in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722813#M224185</link>
    <description>&lt;P&gt;This is your code, with the logic made visible:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Pop6;
set All1;
where
  (
    not missing(Dato_diagnose)
    and
    Labsvar_resultid1="03"
  )
  or
  Labsvar_resultid2="03"
  or
  Labsvar_resultid3="03"
  or
  Labsvar_resultid4="03"
  or
  (
    Labsvar_resultid5="03"
    and
    missing(Koloskopi1_dt)
    and
    missing(Koloskopi2_dt)
    and
    missing(Koloskopi3_dt)
    and
    missing(Koloskopi4_dt)
    and
    missing(Koloskopi5_dt)
  )
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added parentheses (which do not change the logic!) to illustrate the precedence of AND before OR.&lt;/P&gt;
&lt;P&gt;First, the ANDs are evaluated, and the results combined with the ORs&lt;/P&gt;</description>
    <pubDate>Tue, 02 Mar 2021 10:34:42 GMT</pubDate>
    <dc:creator>Kurt_Bremser</dc:creator>
    <dc:date>2021-03-02T10:34:42Z</dc:date>
    <item>
      <title>output does not match code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722802#M224182</link>
      <description>&lt;P&gt;Dear all.&lt;/P&gt;&lt;P&gt;I need help.&lt;/P&gt;&lt;P&gt;I am creating population for a big national study. and while creating the last population I encountered a challenge. As I see it my outcome does not match.&lt;/P&gt;&lt;P&gt;I want to end up with a dataset where all contains the variable Dato_diagnose, all contain one of the following: Labsvar_resultid1="03",&amp;nbsp;Labsvar_resultid2="03", Labsvar_resultid3="03", Labsvar_resultid4="03", Labsvar_resultid5="03" and does not contain any of the following: Koloskopi1_dt,&amp;nbsp;Koloskopi2_dt,&amp;nbsp;Koloskopi3_dt,&amp;nbsp;Koloskopi4_dt, Koloskopi5_dt.&lt;/P&gt;&lt;P&gt;my code is this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data Pop6;&lt;/P&gt;&lt;P&gt;set All1;&lt;/P&gt;&lt;P&gt;where not missing(Dato_diagnose) and Labsvar_resultid1="03" or&amp;nbsp;Labsvar_resultid2="03" or Labsvar_resultid3="03" or Labsvar_resultid4="03" or Labsvar_resultid5="03" and missing(Koloskopi1_dt) and&amp;nbsp; missing(Koloskopi2_dt) and missing(Koloskopi3_dt) and missing(Koloskopi4_dt) and missing(Koloskopi5_dt);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;SAS runs the code, but the output contains missing data on Dato_diagnosis and it contains all the Koloskopi1_dt etc.&lt;/P&gt;&lt;P&gt;what have I done wrong?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;kind regards&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 08:06:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722802#M224182</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2021-03-02T08:06:17Z</dc:date>
    </item>
    <item>
      <title>Re: output does not match code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722813#M224185</link>
      <description>&lt;P&gt;This is your code, with the logic made visible:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data Pop6;
set All1;
where
  (
    not missing(Dato_diagnose)
    and
    Labsvar_resultid1="03"
  )
  or
  Labsvar_resultid2="03"
  or
  Labsvar_resultid3="03"
  or
  Labsvar_resultid4="03"
  or
  (
    Labsvar_resultid5="03"
    and
    missing(Koloskopi1_dt)
    and
    missing(Koloskopi2_dt)
    and
    missing(Koloskopi3_dt)
    and
    missing(Koloskopi4_dt)
    and
    missing(Koloskopi5_dt)
  )
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I added parentheses (which do not change the logic!) to illustrate the precedence of AND before OR.&lt;/P&gt;
&lt;P&gt;First, the ANDs are evaluated, and the results combined with the ORs&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 10:34:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722813#M224185</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-02T10:34:42Z</dc:date>
    </item>
    <item>
      <title>Re: output does not match code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722817#M224188</link>
      <description>Thank you so much. Now it works. You are a real hero!</description>
      <pubDate>Tue, 02 Mar 2021 09:06:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722817#M224188</guid>
      <dc:creator>Jannie_D</dc:creator>
      <dc:date>2021-03-02T09:06:46Z</dc:date>
    </item>
    <item>
      <title>Re: output does not match code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722818#M224189</link>
      <description>&lt;P&gt;Code without data does not show anything about "output does not match code". You would need to provide 1) some starting values for the variables in form of a data step and 2) the expected values that are not matching expectation, again in the form of a data step.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Boolean combinations of AND and OR really require knowing how the order of operations apply results.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can test whether any of a list of variables has a specific value using the WHICHC, for character values, or WHICHN, for numeric values. The function will return the first position in the list where the value is found or 0 if not found. So "Labsvar_resultid1="03" or Labsvar_resultid2="03" or Labsvar_resultid3="03" or Labsvar_resultid4="03" or Labsvar_resultid5="03"&amp;nbsp; " could be replaced with: &lt;/P&gt;
&lt;P&gt;Whichc('03',Labsvar_resultid1,Labsvar_resultid2,Labsvar_resultid3,Labsvar_resultid4,Labsvar_resultid5) &amp;gt; 0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You do not mention if Koloskopi1_dt and related are numeric or character values. If they are numeric you could replace:&lt;/P&gt;
&lt;P&gt;missing(Koloskopi1_dt) and missing(Koloskopi2_dt) and missing(Koloskopi3_dt) and missing(Koloskopi4_dt) and missing(Koloskopi5_dt)&lt;/P&gt;
&lt;P&gt;with&lt;/P&gt;
&lt;P&gt;Nmiss(Koloskopi1_dt, Koloskopi2_dt,Koloskopi3_dt,Koloskopi4_dt,Koloskopi5_dt) = 5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Which would reduce the whole thing to two ANDs:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Where not missing(Dato_diagnose)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; and (Whichc('03',Labsvar_resultid1,Labsvar_resultid2,Labsvar_resultid3,Labsvar_resultid4,Labsvar_resultid5) &amp;gt; 0)&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; and (Nmiss(Koloskopi1_dt, Koloskopi2_dt,Koloskopi3_dt,Koloskopi4_dt,Koloskopi5_dt) = 5)&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 09:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722818#M224189</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-02T09:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: output does not match code</title>
      <link>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722831#M224198</link>
      <description>&lt;P&gt;Note that the code I posted shows the importance of proper code formatting. For this, also study Maxim 12.&lt;/P&gt;</description>
      <pubDate>Tue, 02 Mar 2021 10:36:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/output-does-not-match-code/m-p/722831#M224198</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-03-02T10:36:46Z</dc:date>
    </item>
  </channel>
</rss>

