<?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: IF statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793403#M254300</link>
    <description>&lt;P&gt;If you think it worked before perhaps the data is different?&amp;nbsp; Maybe the value that looks like 1 is not exactly 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If is hard to tell what you want to happen.&amp;nbsp; But here is a way for you to examine the impact the tests you are doing.&amp;nbsp; Let's make a dummy dataset with some values of RULE and STATUS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results;
  do rule='Rule 1','Rule 2','Other';
    do status=1,2;
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's create some binary 1/0 variables from the various conditions you are testing.&lt;/P&gt;
&lt;PRE&gt;data TEST;
  set RESULTS;
  r1= rule ne 'Rule 1';
  r2= rule ne 'Rule 2';
  r3= rule ne 'Rule 3';
  s1= status ne 1;

  test1= r1 and s1;
  test2= r2 and s1;
  test3= r3 and s1;
run;&lt;/PRE&gt;
&lt;P&gt;So the R1-R3 variables are the various RULE NE xxx conditions.&amp;nbsp; The S1 variable test if STATUS is no one.&lt;/P&gt;
&lt;P&gt;Then the TEST1-TEST3 show the impact of using AND with one of the R variables and the S variables.&lt;/P&gt;
&lt;P&gt;So TEST1 was what you original code was testing.&lt;/P&gt;
&lt;PRE&gt;Obs     rule     status    r1    r2    r3    s1    test1    test2    test3

 1     Rule 1       1       0     1     1     0      0        0        0
 2     Rule 1       2       0     1     1     1      0        1        1
 3     Rule 2       1       1     0     1     0      0        0        0
 4     Rule 2       2       1     0     1     1      1        0        1
 5     Other        1       1     1     1     0      0        0        0
 6     Other        2       1     1     1     1      1        1        1
&lt;/PRE&gt;
&lt;P&gt;So which of these 6 observations did you actually want to select?&lt;/P&gt;</description>
    <pubDate>Sun, 30 Jan 2022 20:28:33 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-01-30T20:28:33Z</dc:date>
    <item>
      <title>IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793374#M254283</link>
      <description>&lt;P&gt;I am having an issue with a certain piece of my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data RESULTS;&lt;BR /&gt;set TESTDATA;&lt;BR /&gt;if RULE NE 'ABC' AND STATUS NE 1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run this,&amp;nbsp; if the RULE is NE 'ABC' and the STATUS is EQ 2,&amp;nbsp;the data does not show up because it only looks at the 1st statement. Please help!&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 15:52:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793374#M254283</guid>
      <dc:creator>aiabamba</dc:creator>
      <dc:date>2022-01-30T15:52:29Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793380#M254288</link>
      <description>&lt;P&gt;can you post some sample data as datalines? also, for AND, both conditions have to be true.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:01:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793380#M254288</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-01-30T16:01:15Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793384#M254290</link>
      <description>&lt;P&gt;I think code is correct...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data testdata;
  input RULE $ STATUS;
datalines;
ABC 1
AAA 1
AAA 2
ABC 2
;
run;

data RESULTS;
set TESTDATA;
if RULE NE 'ABC' AND STATUS NE 1;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="2022-01-31_01h12_58.png" style="width: 241px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/67978i5BF10EADC1B19BC7/image-size/large?v=v2&amp;amp;px=999" role="button" title="2022-01-31_01h12_58.png" alt="2022-01-31_01h12_58.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show up what data you are using.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:14:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793384#M254290</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2022-01-30T16:14:30Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793387#M254292</link>
      <description>&lt;P&gt;Here is an example:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE border="0" cellspacing="0" cellpadding="0"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;ID&lt;/TD&gt;&lt;TD&gt;RULE&lt;/TD&gt;&lt;TD&gt;STATUS&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;This should not show up and it doesn't&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;123&lt;/TD&gt;&lt;TD&gt;ABC&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;&lt;TD&gt;This does not show up when it should&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:21:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793387#M254292</guid>
      <dc:creator>aiabamba</dc:creator>
      <dc:date>2022-01-30T16:21:16Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793389#M254293</link>
      <description>&lt;P&gt;the second one will not show up because you put rule ne 'ABC'. since rule='ABC', it will not show up.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:26:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793389#M254293</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-01-30T16:26:15Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793390#M254294</link>
      <description>&lt;P&gt;Is there a way for the 2nd line to show up? I need it to apply BOTH conditions. I already tried putting the statements in parenthesis.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:42:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793390#M254294</guid>
      <dc:creator>aiabamba</dc:creator>
      <dc:date>2022-01-30T16:42:51Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793391#M254295</link>
      <description>&lt;P&gt;your logic is wrong. my point was that as long as you have if rule ne 'ABC', then the second one will never show up. the parentheses will not fix that either. if you need the second one to show, then you must get rid of rule ne ABC.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:47:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793391#M254295</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-01-30T16:47:42Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793392#M254296</link>
      <description>&lt;P&gt;I see. Interesting enough, I have other rules and the statements worked. It is only this one particular line that does work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data TEST;&lt;BR /&gt;set RESULTS;&lt;BR /&gt;if RULE NE ‘Rule 1’; - This works&lt;BR /&gt;if RULE NE ‘Rule 2’ and status NE 1; - Does not work&lt;BR /&gt;if RULE NE 'Rule 3’ and status NE 1; - Works&lt;BR /&gt;if RULE NE ‘Rule 4’ and status NE 1; - Works&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 16:53:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793392#M254296</guid>
      <dc:creator>aiabamba</dc:creator>
      <dc:date>2022-01-30T16:53:00Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793394#M254297</link>
      <description>&lt;P&gt;I don't think you understand how AND works or else you have written your code according to incorrect logic. It's not entirely clear to me what you're trying to do but if you want the second one to be included based on sample data you provided, then you would just do if status ne 1.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 17:06:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793394#M254297</guid>
      <dc:creator>tarheel13</dc:creator>
      <dc:date>2022-01-30T17:06:09Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793399#M254298</link>
      <description>&lt;P&gt;I do.&amp;nbsp;This code actually worked before and I just needed a re-run. I wanted to create a sub-set data based on the text contained under the RULE column and the status. It worked for some statements but not for a particular statement.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your inputs. I will try and find a way to fix it.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 17:37:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793399#M254298</guid>
      <dc:creator>aiabamba</dc:creator>
      <dc:date>2022-01-30T17:37:38Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793403#M254300</link>
      <description>&lt;P&gt;If you think it worked before perhaps the data is different?&amp;nbsp; Maybe the value that looks like 1 is not exactly 1?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If is hard to tell what you want to happen.&amp;nbsp; But here is a way for you to examine the impact the tests you are doing.&amp;nbsp; Let's make a dummy dataset with some values of RULE and STATUS.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data results;
  do rule='Rule 1','Rule 2','Other';
    do status=1,2;
      output;
    end;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Now let's create some binary 1/0 variables from the various conditions you are testing.&lt;/P&gt;
&lt;PRE&gt;data TEST;
  set RESULTS;
  r1= rule ne 'Rule 1';
  r2= rule ne 'Rule 2';
  r3= rule ne 'Rule 3';
  s1= status ne 1;

  test1= r1 and s1;
  test2= r2 and s1;
  test3= r3 and s1;
run;&lt;/PRE&gt;
&lt;P&gt;So the R1-R3 variables are the various RULE NE xxx conditions.&amp;nbsp; The S1 variable test if STATUS is no one.&lt;/P&gt;
&lt;P&gt;Then the TEST1-TEST3 show the impact of using AND with one of the R variables and the S variables.&lt;/P&gt;
&lt;P&gt;So TEST1 was what you original code was testing.&lt;/P&gt;
&lt;PRE&gt;Obs     rule     status    r1    r2    r3    s1    test1    test2    test3

 1     Rule 1       1       0     1     1     0      0        0        0
 2     Rule 1       2       0     1     1     1      0        1        1
 3     Rule 2       1       1     0     1     0      0        0        0
 4     Rule 2       2       1     0     1     1      1        0        1
 5     Other        1       1     1     1     0      0        0        0
 6     Other        2       1     1     1     1      1        1        1
&lt;/PRE&gt;
&lt;P&gt;So which of these 6 observations did you actually want to select?&lt;/P&gt;</description>
      <pubDate>Sun, 30 Jan 2022 20:28:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-statement/m-p/793403#M254300</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-01-30T20:28:33Z</dc:date>
    </item>
  </channel>
</rss>

