<?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: Aggregate and Calculate by Jurisdiction and Overall in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355220#M83202</link>
    <description>&lt;P&gt;For the sake of posterity:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE REPORT AS
SELECT 'OVERALL' AS Jurisdiction
, SUM(CASE WHEN BUILDINGTYPE = 'private' THEN ENR ELSE . END)/SUM(CASE WHEN BUILDINGTYPE = 'private' AND ENR IS NOT NULL THEN 1 ELSE 0 END) As Private
, SUM(CASE WHEN BUILDINGTYPE = 'public' THEN ENR ELSE .  END)/SUM(CASE WHEN BUILDINGTYPE = 'public' AND ENR IS NOT NULL THEN 1 ELSE 0 END) as Public
FROM HAVE
UNION ALL
SELECT DISTINCT 'Jurisdiction', ., . FROM HAVE
UNION ALL
SELECT jurisdictn
, SUM(CASE WHEN BUILDINGTYPE = 'private' THEN ENR ELSE .  END)/SUM(CASE WHEN BUILDINGTYPE = 'private' AND ENR IS NOT NULL THEN 1 ELSE 0 END) As Private
, SUM(CASE WHEN BUILDINGTYPE = 'public' THEN ENR ELSE .  END)/SUM(CASE WHEN BUILDINGTYPE = 'public' AND ENR IS NOT NULL THEN 1 ELSE 0 END) as Public
FROM HAVE
GROUP BY jurisdictn
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Tue, 02 May 2017 12:25:03 GMT</pubDate>
    <dc:creator>thomp7050</dc:creator>
    <dc:date>2017-05-02T12:25:03Z</dc:date>
    <item>
      <title>Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355072#M83151</link>
      <description>&lt;PRE&gt;   infile datalines missover;
   informat buildingname $10. buildingtype $8. responded $1. jurisdictn $9. enr best5. ;
   input buildingname 1-10  buildingtype  responded  jurisdictn  enr  ;
cards;
happy days private Y nottingha 100
learning   public  N nottingha
buildingbl private Y nottingha 55
montessori private N nottingha
bean stalk private Y brunswick 55
learning   private Y brunswick 22
early lear private Y brunswick 255
childtime  private N brunswick
risingstar public  N brunswick
doodlebugs public  Y brunswick 34
;

run;

proc means data=have mean;
  class jurisdictn buildingtype;
  var enr;
run;

proc tabulate data=have;
  class jurisdictn buildingtype;
  var enr;
  table  jurisdictn,
         buildingtype * enr*mean;
run;
 
&lt;/PRE&gt;
&lt;P&gt;Hi, I forgot to ask in a &lt;A href="https://communities.sas.com/t5/Base-SAS-Programming/Summarize-and-calcluate/m-p/355008#M83131" target="_self"&gt;previous post&lt;/A&gt;, how to get output overall and by jurisdiction. The code above gives output by jurisdication.&amp;nbsp; How do I get output with mean for all public buildings listed on the first line,&amp;nbsp; the individual jurisdictions below it? Same for private&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the data above, I need to&amp;nbsp;sum enr and divide by number that responded 'Y'&amp;nbsp;get the following output&lt;/P&gt;
&lt;P&gt;Calclation:&lt;/P&gt;
&lt;P&gt;Jurisdiction&amp;nbsp; Private&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Public&lt;/P&gt;
&lt;P&gt;Overall&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;(100+55+55+22+255)/5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;34/1&lt;/P&gt;
&lt;P&gt;nottingha&amp;nbsp;&amp;nbsp;&amp;nbsp; (100+55)/2&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;brunswick&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (55+22+255)/3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;34/1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Results:&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Jurisdiction&amp;nbsp; Private&amp;nbsp;&amp;nbsp;&amp;nbsp; Public&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;Overall&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;97.4 &amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;34.0&lt;/P&gt;
&lt;P&gt;Jurisdication&lt;/P&gt;
&lt;P&gt;Nottingha&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 77.5&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;BR /&gt;Brunswick&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 110.7&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 34.0&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 20:57:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355072#M83151</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2017-05-01T20:57:41Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355075#M83152</link>
      <description>&lt;P&gt;Look at the ALL keyword in PROC TABULATE.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, your code was cut off in your copy and paste.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 21:00:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355075#M83152</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-01T21:00:52Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355078#M83154</link>
      <description>&lt;P&gt;Plenty of ways to do this. &amp;nbsp;Here's one:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
infile datalines missover;
informat buildingname $10. buildingtype $8. responded $1. jurisdictn $9. enr best5. ;
input buildingname 1-10  buildingtype  responded  jurisdictn  enr  ;
cards;
happy days private Y nottingha 100
learning   public  N nottingha
buildingbl private Y nottingha 55
montessori private N nottingha
bean stalk private Y brunswick 55
learning   private Y brunswick 22
early lear private Y brunswick 255
childtime  private N brunswick
risingstar public  N brunswick
doodlebugs public  Y brunswick 34
;

run;

proc means data=have mean;
  class jurisdictn buildingtype;
  var enr;
run;

proc tabulate data=have;
  class jurisdictn buildingtype;
  var enr;
  table  jurisdictn,
         buildingtype * enr*mean;
run;

PROC SQL;
CREATE TABLE REPORT AS
SELECT 'OVERALL' AS Jurisdiction
, SUM(CASE WHEN BUILDINGTYPE = 'private' THEN ENR END)/SUM(CASE WHEN BUILDINGTYPE = 'private' AND ENR IS NOT NULL THEN 1 ELSE 0 END) As Private
, SUM(CASE WHEN BUILDINGTYPE = 'public' THEN ENR END)/SUM(CASE WHEN BUILDINGTYPE = 'public' AND ENR IS NOT NULL THEN 1 ELSE 0 END) as Public
FROM HAVE
UNION ALL
SELECT DISTINCT 'Jurisdiction', ., . FROM HAVE
UNION ALL
SELECT jurisdictn
, SUM(CASE WHEN BUILDINGTYPE = 'private' THEN ENR END)/SUM(CASE WHEN BUILDINGTYPE = 'private' AND ENR IS NOT NULL THEN 1 ELSE 0 END) As Private
, SUM(CASE WHEN BUILDINGTYPE = 'public' THEN ENR END)/SUM(CASE WHEN BUILDINGTYPE = 'public' AND ENR IS NOT NULL THEN 1 ELSE 0 END) as Public
FROM HAVE
GROUP BY jurisdictn
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2017 21:10:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355078#M83154</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-05-01T21:10:02Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355080#M83155</link>
      <description>&lt;P&gt;Also, I know this is sample data but your jurisdictions value is being truncated here so make sure to fix that in your actual data.&lt;/P&gt;</description>
      <pubDate>Mon, 01 May 2017 21:27:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355080#M83155</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-01T21:27:50Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355083#M83158</link>
      <description>&lt;P&gt;Maybe&lt;/P&gt;
&lt;PRE&gt;proc tabulate data=have;
  class jurisdictn buildingtype;
  var enr;
  table  all jurisdictn='',
         buildingtype='' * enr=''*mean=''*f=best6.;
run;&lt;/PRE&gt;</description>
      <pubDate>Mon, 01 May 2017 21:44:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355083#M83158</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-05-01T21:44:14Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355110#M83168</link>
      <description>&lt;P&gt;Thanks Everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question, for the proc sql procedure, do I need be concerned about this in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: Table WORK.REPORT created, with 60 rows and 3 columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 00:38:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355110#M83168</guid>
      <dc:creator>jcis7</dc:creator>
      <dc:date>2017-05-02T00:38:22Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355111#M83169</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/40498"&gt;@jcis7&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Thanks Everyone!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Question, for the proc sql procedure, do I need be concerned about this in the log:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: A CASE expression has no ELSE clause. Cases not accounted for by the WHEN clauses will&lt;/P&gt;
&lt;P&gt;result in a missing value for the CASE expression.&lt;/P&gt;
&lt;P&gt;NOTE: Table WORK.REPORT created, with 60 rows and 3 columns&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;IMO I would correct this.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 May 2017 00:49:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355111#M83169</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-05-02T00:49:06Z</dc:date>
    </item>
    <item>
      <title>Re: Aggregate and Calculate by Jurisdiction and Overall</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355220#M83202</link>
      <description>&lt;P&gt;For the sake of posterity:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;PROC SQL;
CREATE TABLE REPORT AS
SELECT 'OVERALL' AS Jurisdiction
, SUM(CASE WHEN BUILDINGTYPE = 'private' THEN ENR ELSE . END)/SUM(CASE WHEN BUILDINGTYPE = 'private' AND ENR IS NOT NULL THEN 1 ELSE 0 END) As Private
, SUM(CASE WHEN BUILDINGTYPE = 'public' THEN ENR ELSE .  END)/SUM(CASE WHEN BUILDINGTYPE = 'public' AND ENR IS NOT NULL THEN 1 ELSE 0 END) as Public
FROM HAVE
UNION ALL
SELECT DISTINCT 'Jurisdiction', ., . FROM HAVE
UNION ALL
SELECT jurisdictn
, SUM(CASE WHEN BUILDINGTYPE = 'private' THEN ENR ELSE .  END)/SUM(CASE WHEN BUILDINGTYPE = 'private' AND ENR IS NOT NULL THEN 1 ELSE 0 END) As Private
, SUM(CASE WHEN BUILDINGTYPE = 'public' THEN ENR ELSE .  END)/SUM(CASE WHEN BUILDINGTYPE = 'public' AND ENR IS NOT NULL THEN 1 ELSE 0 END) as Public
FROM HAVE
GROUP BY jurisdictn
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 02 May 2017 12:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Aggregate-and-Calculate-by-Jurisdiction-and-Overall/m-p/355220#M83202</guid>
      <dc:creator>thomp7050</dc:creator>
      <dc:date>2017-05-02T12:25:03Z</dc:date>
    </item>
  </channel>
</rss>

