<?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 then else statement with three conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485635#M126190</link>
    <description>&lt;P&gt;I am doing the following and it seems working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if .&amp;lt;a&amp;gt;0 AND b='buy' AND c&amp;lt;0 then new=1;
else if .&amp;lt;a&amp;lt;0 AND b='sell' AND c&amp;gt;0 then new=1;
else new=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Fri, 10 Aug 2018 00:22:31 GMT</pubDate>
    <dc:creator>Saba1</dc:creator>
    <dc:date>2018-08-10T00:22:31Z</dc:date>
    <item>
      <title>if then else statement with three conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485617#M126186</link>
      <description>&lt;P&gt;&amp;nbsp;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to create a variable by using "if then else" statement and specify &lt;STRONG&gt;three conditions&lt;/STRONG&gt; about the variables in my dataset.&amp;nbsp;I want that "new" variable must be equal to "1" only when all three specified conditions are met and if any one of the conditions is missing, it must be equal to "0".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example, my code is:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if a&amp;gt;0 AND b='buy' AND c&amp;lt;0 then new=1;
else if a&amp;lt;0 AND b='sell' AND c&amp;gt;0 then new=1;
else new=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;The resulting "new" variable is equal to "1" when all three conditions are met. But it is also equal to "1" when first variable i.e. "a" is having a missing value in the data, and in this case only last two conditions (i.e. variable b and c) are considered. Whereas, I want new=1 only when all three conditions are met.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Kindly guide me where am I doing the mistake.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 22:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485617#M126186</guid>
      <dc:creator>Saba1</dc:creator>
      <dc:date>2018-08-09T22:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: if then else statement with three conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485619#M126187</link>
      <description>&lt;P&gt;Missing is always considered "less than" any thing. Try using&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="token keyword"&gt;else&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt;&amp;nbsp; . &amp;lt; a &lt;SPAN class="token operator"&gt;&amp;lt;&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; AND b&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'sell'&lt;/SPAN&gt; AND c&lt;SPAN class="token operator"&gt;&amp;gt;&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;0&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; new&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 09 Aug 2018 22:46:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485619#M126187</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-08-09T22:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: if then else statement with three conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485635#M126190</link>
      <description>&lt;P&gt;I am doing the following and it seems working:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
if .&amp;lt;a&amp;gt;0 AND b='buy' AND c&amp;lt;0 then new=1;
else if .&amp;lt;a&amp;lt;0 AND b='sell' AND c&amp;gt;0 then new=1;
else new=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Fri, 10 Aug 2018 00:22:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/if-then-else-statement-with-three-conditions/m-p/485635#M126190</guid>
      <dc:creator>Saba1</dc:creator>
      <dc:date>2018-08-10T00:22:31Z</dc:date>
    </item>
  </channel>
</rss>

