<?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: OR &amp; AND operators in IF statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14771#M1893</link>
    <description>Let's go through the logic of your subsetting if statement.&lt;BR /&gt;
&lt;BR /&gt;
The first record x=12, y=as&lt;BR /&gt;
Your logic:   if y ne 'as' or y ne 'aq';&lt;BR /&gt;
&lt;BR /&gt;
y ne 'as', so that is false&lt;BR /&gt;
y ne 'aq', so that is true &lt;BR /&gt;
&lt;BR /&gt;
With an OR statement any true resolves to true, hence false or true will resolve to true.  With an AND both statements need to be true for it to resolve to true, which is why the AND works and the or does not&lt;BR /&gt;
&lt;BR /&gt;
BTW: SAS has a function called NOTDIGIT which searches a character string for any character that is not a digit and returns the first position at which that character is found &lt;BR /&gt;
&lt;BR /&gt;
* For Example;&lt;BR /&gt;
data sample2;&lt;BR /&gt;
  set sample;&lt;BR /&gt;
  num_check=notdigit(strip(y));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data what_i_want;&lt;BR /&gt;
  set sample2;&lt;BR /&gt;
  if num_check then delete;&lt;BR /&gt;
run;</description>
    <pubDate>Wed, 30 Apr 2008 12:22:47 GMT</pubDate>
    <dc:creator>darrylovia</dc:creator>
    <dc:date>2008-04-30T12:22:47Z</dc:date>
    <item>
      <title>OR &amp; AND operators in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14770#M1892</link>
      <description>I have a dataset which is created using datastep as shown below.&lt;BR /&gt;
data sample;&lt;BR /&gt;
input x y $;&lt;BR /&gt;
datalines;&lt;BR /&gt;
12 as&lt;BR /&gt;
15 24&lt;BR /&gt;
14 aq&lt;BR /&gt;
16 26&lt;BR /&gt;
10 15&lt;BR /&gt;
;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
I want the output dataset to be &lt;BR /&gt;
    x	y&lt;BR /&gt;
   15	24&lt;BR /&gt;
   16	26&lt;BR /&gt;
   10	15   &lt;BR /&gt;
i.e. subsetting the obeservation where y should have only numeric values.&lt;BR /&gt;
&lt;BR /&gt;
When I use the SAS code,&lt;BR /&gt;
&lt;BR /&gt;
data sample1;&lt;BR /&gt;
set sample;&lt;BR /&gt;
if y ne 'as' or y ne 'aq';&lt;BR /&gt;
run;&lt;BR /&gt;
I'm not getting the desired output instead I have all the data points.&lt;BR /&gt;
&lt;BR /&gt;
But the desired output is obtained when the following SAS code is used.&lt;BR /&gt;
&lt;BR /&gt;
data sample1;&lt;BR /&gt;
set sample;&lt;BR /&gt;
if y ne 'as' and y ne 'aq';&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
Usually the generic understanding is whenever we don't want either 'as' or 'aq', we can use OR operator in IF statement. But in the given code it works well using AND operator. Can anyone give the explanation on how does SAS work when these OR &amp;amp; AND operators are used in the IF statement?&lt;BR /&gt;
&lt;BR /&gt;
-Suresh.</description>
      <pubDate>Wed, 30 Apr 2008 06:05:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14770#M1892</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-30T06:05:27Z</dc:date>
    </item>
    <item>
      <title>Re: OR &amp; AND operators in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14771#M1893</link>
      <description>Let's go through the logic of your subsetting if statement.&lt;BR /&gt;
&lt;BR /&gt;
The first record x=12, y=as&lt;BR /&gt;
Your logic:   if y ne 'as' or y ne 'aq';&lt;BR /&gt;
&lt;BR /&gt;
y ne 'as', so that is false&lt;BR /&gt;
y ne 'aq', so that is true &lt;BR /&gt;
&lt;BR /&gt;
With an OR statement any true resolves to true, hence false or true will resolve to true.  With an AND both statements need to be true for it to resolve to true, which is why the AND works and the or does not&lt;BR /&gt;
&lt;BR /&gt;
BTW: SAS has a function called NOTDIGIT which searches a character string for any character that is not a digit and returns the first position at which that character is found &lt;BR /&gt;
&lt;BR /&gt;
* For Example;&lt;BR /&gt;
data sample2;&lt;BR /&gt;
  set sample;&lt;BR /&gt;
  num_check=notdigit(strip(y));&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data what_i_want;&lt;BR /&gt;
  set sample2;&lt;BR /&gt;
  if num_check then delete;&lt;BR /&gt;
run;</description>
      <pubDate>Wed, 30 Apr 2008 12:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14771#M1893</guid>
      <dc:creator>darrylovia</dc:creator>
      <dc:date>2008-04-30T12:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: OR &amp; AND operators in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14772#M1894</link>
      <description>Hi Darrylovia,&lt;BR /&gt;
&lt;BR /&gt;
Thanks for your reply and time.&lt;BR /&gt;
I understood the concept from your nice explanation.&lt;BR /&gt;
&lt;BR /&gt;
Regards,&lt;BR /&gt;
Suresh.</description>
      <pubDate>Wed, 30 Apr 2008 12:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14772#M1894</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-30T12:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: OR &amp; AND operators in IF statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14773#M1895</link>
      <description>It is not a SAS thing, but a Boolean Logic thing.&lt;BR /&gt;
&lt;BR /&gt;
not (A or B) = not A  and  not B</description>
      <pubDate>Wed, 30 Apr 2008 14:19:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/OR-AND-operators-in-IF-statement/m-p/14773#M1895</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2008-04-30T14:19:12Z</dc:date>
    </item>
  </channel>
</rss>

