<?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 Need help undestanding unique CASE END WHEN THEN logic in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336597#M76316</link>
    <description>&lt;P&gt;I&amp;nbsp;am currently porting report summary SQL from COGNOS Report Sudio to SAS EG.&amp;nbsp;The SQL in the below segment&amp;nbsp;defines a sub-total label for&amp;nbsp;widgets in 2 different grouping categories. I know widget&amp;nbsp;(type)&amp;nbsp;is suppose to resolve to a range of either 1-11 or 13-28 based on its subtype,&amp;nbsp;but I am baffled how this logic works once it finishes the inner most case statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone help me understand the logic of the 5th line from the bottom&amp;nbsp; i.e. "&lt;STRONG&gt;end&amp;nbsp; &amp;lt; 1&lt;/STRONG&gt;"&amp;nbsp; and how it pertains to the remaining 4 lines? I see the obvious logic&amp;nbsp;but it does not make sense to me as applied to the result, specifically the&amp;nbsp;"&lt;STRONG&gt;end&amp;nbsp; &amp;lt; 1&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;Here is and abridged version of the SQL segment:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;case  
 when 
  case  
   when 
    (case  
     when (Widget.SubType in (100, 105, 110, 115)) then 1 
     when (Widget.SubType in (140, 145)) then 3 
     ........... 
     ...........
     when (Widget.SubType in (133, 138)) then 11 
     when (Widget.SubType in (71, 72)) then 13 
     when (Widget.SubType in (80, 81, 85, 88)) then 14 
     ...........
     ...........
     when (Widget.SubType in (200, 201, 202, 205, 210, 215, 225, 230, 235)) then 28 
     else 999 
    end  &amp;lt; 1) 
   then '1' else '2' 
  end  = '1' 
 then 'Widget Types 1 through 11' else 'Widget Types 13 through 28' 
end &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2017 15:31:04 GMT</pubDate>
    <dc:creator>eg_michael</dc:creator>
    <dc:date>2017-02-28T15:31:04Z</dc:date>
    <item>
      <title>Need help undestanding unique CASE END WHEN THEN logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336597#M76316</link>
      <description>&lt;P&gt;I&amp;nbsp;am currently porting report summary SQL from COGNOS Report Sudio to SAS EG.&amp;nbsp;The SQL in the below segment&amp;nbsp;defines a sub-total label for&amp;nbsp;widgets in 2 different grouping categories. I know widget&amp;nbsp;(type)&amp;nbsp;is suppose to resolve to a range of either 1-11 or 13-28 based on its subtype,&amp;nbsp;but I am baffled how this logic works once it finishes the inner most case statement.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could someone help me understand the logic of the 5th line from the bottom&amp;nbsp; i.e. "&lt;STRONG&gt;end&amp;nbsp; &amp;lt; 1&lt;/STRONG&gt;"&amp;nbsp; and how it pertains to the remaining 4 lines? I see the obvious logic&amp;nbsp;but it does not make sense to me as applied to the result, specifically the&amp;nbsp;"&lt;STRONG&gt;end&amp;nbsp; &amp;lt; 1&lt;/STRONG&gt;".&lt;/P&gt;&lt;P&gt;Here is and abridged version of the SQL segment:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;case  
 when 
  case  
   when 
    (case  
     when (Widget.SubType in (100, 105, 110, 115)) then 1 
     when (Widget.SubType in (140, 145)) then 3 
     ........... 
     ...........
     when (Widget.SubType in (133, 138)) then 11 
     when (Widget.SubType in (71, 72)) then 13 
     when (Widget.SubType in (80, 81, 85, 88)) then 14 
     ...........
     ...........
     when (Widget.SubType in (200, 201, 202, 205, 210, 215, 225, 230, 235)) then 28 
     else 999 
    end  &amp;lt; 1) 
   then '1' else '2' 
  end  = '1' 
 then 'Widget Types 1 through 11' else 'Widget Types 13 through 28' 
end &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 15:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336597#M76316</guid>
      <dc:creator>eg_michael</dc:creator>
      <dc:date>2017-02-28T15:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: Need help undestanding unique CASE END WHEN THEN logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336607#M76322</link>
      <description>&lt;P&gt;I haven't seen such logic in ANSI SQL, so my guess is that this is Cognos specific logic. If so, contact your Cognos resource for explanation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Normally, each&amp;nbsp;when should have a condition and I can't see such in the surrounding case-when's.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the first mapping used somewhere else?&lt;/P&gt;
&lt;P&gt;If not, assign the 1-11 and so on directly and skip all the nestings.&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 15:52:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336607#M76322</guid>
      <dc:creator>LinusH</dc:creator>
      <dc:date>2017-02-28T15:52:54Z</dc:date>
    </item>
    <item>
      <title>Re: Need help undestanding unique CASE END WHEN THEN logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336611#M76325</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is how I understand it :&lt;/P&gt;
&lt;P&gt;The part&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case  
     when (Widget.SubType in (100, 105, 110, 115)) then 1 
     when (Widget.SubType in (140, 145)) then 3 
     ........... 
     ...........
     when (Widget.SubType in (133, 138)) then 11 
     when (Widget.SubType in (71, 72)) then 13 
     when (Widget.SubType in (80, 81, 85, 88)) then 14 
     ...........
     ...........
     when (Widget.SubType in (200, 201, 202, 205, 210, 215, 225, 230, 235)) then 28 
     else 999 
    end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;computes a value based on SubType. If we call X this value, the next step si to evaluate :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;case  
   when  X &amp;lt; 1 
   then '1' else '2' 
  end&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;So if the value reflecting the SubType is less than 1, we set a new value, say Y, to 1. Y=2 instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now if Y=1, then we return the string 'Widegets Type 1 to 11' and 'Widgets Type 13 to 28' otherwise&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Maybe there is a typo and the "&amp;lt;1" should be "&amp;lt;12" ?&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:06:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336611#M76325</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-02-28T16:06:53Z</dc:date>
    </item>
    <item>
      <title>Re: Need help undestanding unique CASE END WHEN THEN logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336618#M76329</link>
      <description>&lt;P&gt;&lt;FONT color="#0000ff"&gt;&lt;EM&gt;Maybe there is a typo and the "&amp;lt;1" should be "&amp;lt;12"&lt;/EM&gt; ?&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;That would make perfect sense with the logic as I see it ... I will ponder that as well and see if I can validate. &lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:26:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336618#M76329</guid>
      <dc:creator>eg_michael</dc:creator>
      <dc:date>2017-02-28T16:26:05Z</dc:date>
    </item>
    <item>
      <title>Re: Need help undestanding unique CASE END WHEN THEN logic</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336628#M76334</link>
      <description>&lt;P&gt;The query seems overly complicated though as intermediary calculations are lost.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
x=110; output;
x=202; output;
x=140; output;
run;

proc sql noprint;
CREATE TABLE want AS
SELECT case when 
         case when 
		    (case  
		     when (x in (100, 105, 110, 115)) then 1 
		     when (x in (140, 145)) then 3 
		     when (x in (133, 138)) then 11 
		     when (x in (71, 72)) then 13 
		     when (x in (80, 81, 85, 88)) then 14 
		     when (x in (200, 201, 202, 205, 210, 215, 225, 230, 235)) then 28 
		     else 999 
		    end  &amp;lt; 12) then '1' else '2' 
		  end  = '1' 
 then 'Widget Types 1 through 11' else 'Widget Types 13 through 28' 
end AS TYPE format=$50.
FROM have;

CREATE TABLE want2 AS
SELECT case when x in (100, 105, 110, 115, 140, 145, 133, 138) then 'Widget Types 1 through 11'
		    else 'Widget Types 13 through 28' 
		    end as TYPE format=$50.
FROM have;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 28 Feb 2017 16:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Need-help-undestanding-unique-CASE-END-WHEN-THEN-logic/m-p/336628#M76334</guid>
      <dc:creator>gamotte</dc:creator>
      <dc:date>2017-02-28T16:40:53Z</dc:date>
    </item>
  </channel>
</rss>

