<?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: SUM function doesn't work on a basic CASE statement output? in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612910#M35302</link>
    <description>&lt;P&gt;I don't see any way around this. You will need two queries or, if you want to avoid creating an intermediate table, two nested queries to do both sums.&lt;/P&gt;</description>
    <pubDate>Thu, 19 Dec 2019 04:20:12 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2019-12-19T04:20:12Z</dc:date>
    <item>
      <title>SUM function doesn't work on a basic CASE statement output?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612832#M35295</link>
      <description>&lt;P&gt;Hi folks,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this SUM function that is giving me the error message:&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;STRONG&gt;ERROR: Summary functions nested in this way are not supported.&lt;/STRONG&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;The block of PROC SQL code that is giving me trouble looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SUM(CASE 
        WHEN 'AoE'n = "BAG"
        THEN (GN.Principal * CALCULATED 'DC Term'n)
        ELSE (GN.Principal * GN.'FAC Term'n)
    END) AS 'FTP LP Y'n &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;When I execute the code without the SUM(), it works and shows all values in the column (calculated from other values). What I need to do is SUM all the values in that column into a singular cell....What is odd to me is that when I used SUM() here, it&amp;nbsp;&lt;STRONG&gt;does&lt;/STRONG&gt; work, which I am using in an earlier portion of my PROC SQL code and it looks like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;SUM(CASE
	  WHEN 'FAC Type'n = "DC"
	  THEN (GN.Principal * GN.'FAC Term'n)
	  ELSE 0
    END) 
/
SUM(CASE
	  WHEN 'FAC Type'n = "DC"
	  THEN GN.Principal
	  ELSE 0
    END) AS 'DC Term'n,&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I can't seem to figure out the differences in syntax between the two blocks of code. Does anyone have any ideas why I might be getting this error?&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 20:44:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612832#M35295</guid>
      <dc:creator>atran2</dc:creator>
      <dc:date>2019-12-18T20:44:39Z</dc:date>
    </item>
    <item>
      <title>Re: SUM function doesn't work on a basic CASE statement output?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612880#M35298</link>
      <description>&lt;P&gt;The problem must be with CALCULATED 'DC Term'n. DC Term must already be a sum. So you basically have SUM(SUM(something)). Show us more for a possible workaround.&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 23:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612880#M35298</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-12-18T23:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: SUM function doesn't work on a basic CASE statement output?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612882#M35299</link>
      <description>&lt;P&gt;Hey you are totally right, which I eventually realized, but still don't know how to get around this since the only way I can think of getting 'DC Term'n is via the sum, which leaves me with a nested sum which PROC SQL seems to dislike. This is the code from 'DC Term'n:&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;SUM(CASE WHEN 'FAC Type'n = "DC"
	 THEN GN.Principal
	 ELSE 0
    END) AS 'DC Term'n&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So currently it seems that what I am basically asking PROC SQL to do is:&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;SUM(CASE WHEN 'AoE'n = "BAG"
       THEN GN.Principal * SUM(CASE WHEN 'FAC Type'n = "DC" THEN GN.Principal ELSE 0 END)
       ELSE GN.Principal * GN.'FAC Term'n
    END) AS 'FTP LP Y'n &lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;and clearly PROC SQL/SAS does not like that. How would I get around this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Dec 2019 23:53:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612882#M35299</guid>
      <dc:creator>atran2</dc:creator>
      <dc:date>2019-12-18T23:53:23Z</dc:date>
    </item>
    <item>
      <title>Re: SUM function doesn't work on a basic CASE statement output?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612910#M35302</link>
      <description>&lt;P&gt;I don't see any way around this. You will need two queries or, if you want to avoid creating an intermediate table, two nested queries to do both sums.&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 04:20:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612910#M35302</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-12-19T04:20:12Z</dc:date>
    </item>
    <item>
      <title>Re: SUM function doesn't work on a basic CASE statement output?</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612914#M35303</link>
      <description>&lt;P&gt;Please explain what you are trying to do.&amp;nbsp; Please explain what your grouping variable(s) is.&amp;nbsp; Post a small sample set of data (in the form of a data step that we can run to re-create it) and what result you are trying to get.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also is there any reason you need to use SQL instead of just writing normal SAS code?&lt;/P&gt;</description>
      <pubDate>Thu, 19 Dec 2019 04:46:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/SUM-function-doesn-t-work-on-a-basic-CASE-statement-output/m-p/612914#M35303</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-12-19T04:46:34Z</dc:date>
    </item>
  </channel>
</rss>

