<?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 IF Statements Problem with Precedence in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/IF-Statements-Problem-with-Precedence/m-p/299551#M63199</link>
    <description>&lt;P&gt;I'm having an issue with if statements in terms of which if statement takes precedence when the similar conditions are met. Let me explain. This is my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MACID;
  input ApprovedPriceType $ 'GER Pharm'n $ Instate $ Code_MAC $;
datalines;
MAC2501A CVS MACHZ .
MAC5251A CVS MACHZ MAC01
MACCHPCO CVS MACHZ MAC02
MACCHPME CVS MACHZ MACMEDCARE
MACHZ CVS MACJX .
MACIA CVS MACJX MAC01
MACNC CVS MACJX MACMEDCARE&lt;BR /&gt;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MACLIST;
  set MACID;
if ApprovedPriceType in('MAC5251A','MACCHPCO','MACHZ','MACNC') then MAC_List=ApprovedPriceType;
if 'GER Pharm'n='CVS' and Instate='MACHZ' and Code_MAC='MAC02' then MAC_List='MAC02';
if 'GER Pharm'n = 'CVS' and Instate = 'MACHZ' and Code_MAC='MAC01' then MAC_List='MAC2501A1J';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'm trying to do with the first if statement is make it have precedence over any proceeding if statement. So, for example, if the ApprovedPriceType is 'MACCHPCO', I want the MAC_List to be 'MACCHPCO'. The trouble is, once it hits the second if, which matches the conditions of the 'MACCHPCO' line in the data, I get 'MAC02' as the MAC_List. Why is this? I tried flipping the lines and it still didn't work. How can I fix this? Thank you for your help.&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2016 14:07:52 GMT</pubDate>
    <dc:creator>JediApprentice</dc:creator>
    <dc:date>2016-09-20T14:07:52Z</dc:date>
    <item>
      <title>IF Statements Problem with Precedence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statements-Problem-with-Precedence/m-p/299551#M63199</link>
      <description>&lt;P&gt;I'm having an issue with if statements in terms of which if statement takes precedence when the similar conditions are met. Let me explain. This is my data:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MACID;
  input ApprovedPriceType $ 'GER Pharm'n $ Instate $ Code_MAC $;
datalines;
MAC2501A CVS MACHZ .
MAC5251A CVS MACHZ MAC01
MACCHPCO CVS MACHZ MAC02
MACCHPME CVS MACHZ MACMEDCARE
MACHZ CVS MACJX .
MACIA CVS MACJX MAC01
MACNC CVS MACJX MACMEDCARE&lt;BR /&gt;;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And this is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data MACLIST;
  set MACID;
if ApprovedPriceType in('MAC5251A','MACCHPCO','MACHZ','MACNC') then MAC_List=ApprovedPriceType;
if 'GER Pharm'n='CVS' and Instate='MACHZ' and Code_MAC='MAC02' then MAC_List='MAC02';
if 'GER Pharm'n = 'CVS' and Instate = 'MACHZ' and Code_MAC='MAC01' then MAC_List='MAC2501A1J';
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;What I'm trying to do with the first if statement is make it have precedence over any proceeding if statement. So, for example, if the ApprovedPriceType is 'MACCHPCO', I want the MAC_List to be 'MACCHPCO'. The trouble is, once it hits the second if, which matches the conditions of the 'MACCHPCO' line in the data, I get 'MAC02' as the MAC_List. Why is this? I tried flipping the lines and it still didn't work. How can I fix this? Thank you for your help.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statements-Problem-with-Precedence/m-p/299551#M63199</guid>
      <dc:creator>JediApprentice</dc:creator>
      <dc:date>2016-09-20T14:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: IF Statements Problem with Precedence</title>
      <link>https://communities.sas.com/t5/SAS-Programming/IF-Statements-Problem-with-Precedence/m-p/299553#M63200</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use &lt;STRONG&gt;else if &lt;/STRONG&gt;for the 2nd and third statement.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2016 14:15:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/IF-Statements-Problem-with-Precedence/m-p/299553#M63200</guid>
      <dc:creator>Loko</dc:creator>
      <dc:date>2016-09-20T14:15:11Z</dc:date>
    </item>
  </channel>
</rss>

