<?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: Case when multiple condition in expression in SAS Data Science</title>
    <link>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654053#M8312</link>
    <description>&lt;P&gt;Why would you but an ELSE between them?&amp;nbsp; ELSE is for catching all of the observations that do not meet any of the earlier WHEN conditions.&amp;nbsp; &amp;nbsp;If you have multiple WHEN conditions just list then one after the other.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when ENTITY_ID_SF in ('1000','1111') and SEGMENT='NL' then sum(GR_INPUT)/(sum(PREM_RES_GR)/3)
     when ENTITY_ID_SF in ('1000','1111') and SEGMENT='PL' then sum(GR_INPUT)/(sum(PREM_RES_GR)/3) 
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Right now both of your two different conditions will return the same result when they are true.&amp;nbsp; So you could collapse them into one WHEN condition.&amp;nbsp; Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (ENTITY_ID_SF in ('1000','1111') and SEGMENT='NL')
       or (ENTITY_ID_SF in ('1000','1111') and SEGMENT='PL') then sum(GR_INPUT)/(sum(PREM_RES_GR)/3)
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (ENTITY_ID_SF in ('1000','1111') and SEGMENT in ('NL','PL')) then sum(GR_INPUT)/(sum(PREM_RES_GR)/3)
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what are you actually trying to do? Did you expect to get different results based on the value of SEGMENT?&amp;nbsp; If so then show some simple input data and what output you want.&lt;/P&gt;</description>
    <pubDate>Sun, 07 Jun 2020 18:21:53 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2020-06-07T18:21:53Z</dc:date>
    <item>
      <title>Case when multiple condition in expression</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654008#M8309</link>
      <description>&lt;P&gt;I need help writing the case when with multiple conditions to use in 'expression' in DI Job. I'm getting an syntax error if I use below. How to keep adding the conditions in case when? Shouldn't we use 'else' to seperate the condition?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;case when ENTITY_ID_SF in ('1000','1111')  and SEGMENT='NL' then (sum(GR_INPUT)/(sum(PREM_RES_GR)/3)) 
end
else
case when ENTITY_ID_SF in ('1000','1111') and SEGMENT='PL' then (sum(GR_INPUT)/(sum(PREM_RES_GR)/3)) 
end&lt;/PRE&gt;</description>
      <pubDate>Sun, 07 Jun 2020 12:50:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654008#M8309</guid>
      <dc:creator>David_Billa</dc:creator>
      <dc:date>2020-06-07T12:50:00Z</dc:date>
    </item>
    <item>
      <title>Re: Case when multiple condition in expression</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654013#M8310</link>
      <description>&lt;P&gt;try the below code&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;CASE
    WHEN condition1 THEN result1
    WHEN condition2 THEN result2
    WHEN conditionN THEN resultN
    ELSE result
END as variable_name 

&lt;BR /&gt;&lt;BR /&gt;ca&lt;/CODE&gt;se &lt;BR /&gt;when ENTITY_ID_SF in ('1000','1111') and SEGMENT='NL' then (sum(GR_INPUT)/(sum(PREM_RES_GR)/3)) when ENTITY_ID_SF in ('1000','1111') and SEGMENT='PL' then (sum(GR_INPUT)/(sum(PREM_RES_GR)/3)) else . &lt;BR /&gt;end as variable_name&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 14:52:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654013#M8310</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2020-06-07T14:52:36Z</dc:date>
    </item>
    <item>
      <title>Re: Case when multiple condition in expression</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654047#M8311</link>
      <description>&lt;P&gt;Please. Anytime you get an ERROR, copy the entire procedure with the messages from the LOG and show the code plus the errors. Please.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Include the entire procedure because the cause could be something like a missed or extra quote or parentheses in a previous statement than the place that SAS indicates the error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 17:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654047#M8311</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2020-06-07T17:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: Case when multiple condition in expression</title>
      <link>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654053#M8312</link>
      <description>&lt;P&gt;Why would you but an ELSE between them?&amp;nbsp; ELSE is for catching all of the observations that do not meet any of the earlier WHEN conditions.&amp;nbsp; &amp;nbsp;If you have multiple WHEN conditions just list then one after the other.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when ENTITY_ID_SF in ('1000','1111') and SEGMENT='NL' then sum(GR_INPUT)/(sum(PREM_RES_GR)/3)
     when ENTITY_ID_SF in ('1000','1111') and SEGMENT='PL' then sum(GR_INPUT)/(sum(PREM_RES_GR)/3) 
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Right now both of your two different conditions will return the same result when they are true.&amp;nbsp; So you could collapse them into one WHEN condition.&amp;nbsp; Like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (ENTITY_ID_SF in ('1000','1111') and SEGMENT='NL')
       or (ENTITY_ID_SF in ('1000','1111') and SEGMENT='PL') then sum(GR_INPUT)/(sum(PREM_RES_GR)/3)
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;or like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case when (ENTITY_ID_SF in ('1000','1111') and SEGMENT in ('NL','PL')) then sum(GR_INPUT)/(sum(PREM_RES_GR)/3)
end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what are you actually trying to do? Did you expect to get different results based on the value of SEGMENT?&amp;nbsp; If so then show some simple input data and what output you want.&lt;/P&gt;</description>
      <pubDate>Sun, 07 Jun 2020 18:21:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Science/Case-when-multiple-condition-in-expression/m-p/654053#M8312</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2020-06-07T18:21:53Z</dc:date>
    </item>
  </channel>
</rss>

