<?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: Combine multiple If clauses to case when statement in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503305#M134466</link>
    <description>&lt;P&gt;Thank you. How to add the below condition in the following case when code to derive the value for KNKBTY=2 apart from 1,3,4,5 and 6?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if agi ne agi_v           
    then do;                
      knkbty = '1';         
      knkatv = '' ;         
      knkath = '' ;         
      agiteg = agi;         
      link schrijfv;        
   else                        
      knkbty = '2';         
      knkatv = '' ;         
      knkath = '' ;         
      agiteg = agi_v;       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Case when statement which I have right now is as below. I've to add the above condition in the case when to derive value for '2' as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when knkatd ne knkatd_v then '6'
  when agi ne agi_v then '1'
  when knbjpn &amp;gt; knbjpn_v then '3'
  when knkvpb in ('1','2','3') and knkvpb_v in ('4','5') then '3'
  when knkvpb in ('4','5') and knkvpb_v in ('1','2','3') then '3'
  when knbjpn &amp;lt; knbjpn_v then '4'
  else '5'
end&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 11 Oct 2018 05:16:12 GMT</pubDate>
    <dc:creator>Babloo</dc:creator>
    <dc:date>2018-10-11T05:16:12Z</dc:date>
    <item>
      <title>Combine multiple If clauses to case when statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503028#M134356</link>
      <description>&lt;P&gt;Appreciate if someone of you guide me to combine the following if clauses to 'case when...' statement. I want to calculate the variable 'knkbty' and it should have values 1,3,4,5,6.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Oct 2018 05:13:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503028#M134356</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-10-19T05:13:10Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple If clauses to case when statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503038#M134362</link>
      <description>&lt;P&gt;That's kinda messy code, and not workable (there are two unclosed DO blocks). Disregarding the hanging DO statements, I think that what you want may be something like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when knkatd ne knkatd_v then '6'
  when agi ne agi_v then '1'
  when knbjpn &amp;gt; knbjpn_v then '3'
  when knkvpb in ('1','2','3') and knkvpb_v in ('4','5') then '3'
  when knkvpb in ('4','5') and knkvpb_v in ('1','2','3') then '3'
  when knbjpn &amp;lt; knbjpn_v then '4'
  else '5'
end&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Oct 2018 11:40:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503038#M134362</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-10T11:40:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple If clauses to case when statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503129#M134394</link>
      <description>&lt;P&gt;Your first if group&amp;nbsp;tests&amp;nbsp;on the relationship between knbjpn&amp;nbsp;and knbjpn_v, and it&amp;nbsp;exhausts all possible relations&amp;nbsp;(you have one &amp;lt;, one&amp;nbsp;&amp;gt; and one for =).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So your subsequent tests on AGI and KNKATD, if true, will supersede results based on knbjpn.&amp;nbsp; Is that intentional?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming it is, that's why &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;'s response reverses the order of the 3 main IF test groups, but maintains the order within the first group (if, else if, else).&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;
&lt;P&gt;&lt;LI-WRAPPER&gt;&lt;/LI-WRAPPER&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Oct 2018 15:18:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503129#M134394</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-10-10T15:18:40Z</dc:date>
    </item>
    <item>
      <title>Re: Combine multiple If clauses to case when statement</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503305#M134466</link>
      <description>&lt;P&gt;Thank you. How to add the below condition in the following case when code to derive the value for KNKBTY=2 apart from 1,3,4,5 and 6?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  if agi ne agi_v           
    then do;                
      knkbty = '1';         
      knkatv = '' ;         
      knkath = '' ;         
      agiteg = agi;         
      link schrijfv;        
   else                        
      knkbty = '2';         
      knkatv = '' ;         
      knkath = '' ;         
      agiteg = agi_v;       
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Case when statement which I have right now is as below. I've to add the above condition in the case when to derive value for '2' as well.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case
  when knkatd ne knkatd_v then '6'
  when agi ne agi_v then '1'
  when knbjpn &amp;gt; knbjpn_v then '3'
  when knkvpb in ('1','2','3') and knkvpb_v in ('4','5') then '3'
  when knkvpb in ('4','5') and knkvpb_v in ('1','2','3') then '3'
  when knbjpn &amp;lt; knbjpn_v then '4'
  else '5'
end&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 11 Oct 2018 05:16:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Combine-multiple-If-clauses-to-case-when-statement/m-p/503305#M134466</guid>
      <dc:creator>Babloo</dc:creator>
      <dc:date>2018-10-11T05:16:12Z</dc:date>
    </item>
  </channel>
</rss>

