<?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 PROC SQL, group by &amp; total in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61670#M13409</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One possibility would be to use the create table statement in sql, rather than printing the results, and then use proc print with a summary line (e.g., &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002262174.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002262174.htm&lt;/A&gt; )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That would only require one pass thru the data, one pass thru the summaries, and very little extra coding.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Sep 2011 22:17:18 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2011-09-07T22:17:18Z</dc:date>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61669#M13408</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello all, &lt;/P&gt;&lt;P&gt;Is there a easy way to get totals by sub-group and a total overall in the same column?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So that for example in the code below-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table numbers as select A.MRSA_CLASS, put(sum(com)/count(*), percent10.) as compliance,put(sum(TEST)/count(*), percent10.) as TESTED,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;from MRSA_ADM_ARR as a&lt;/P&gt;&lt;P&gt;group by&amp;nbsp; A.MRSA_CLASS;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I will get&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;CLASS Compliance Tested&lt;/P&gt;&lt;P&gt;A&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 75%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 90%&lt;/P&gt;&lt;P&gt;B&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 55%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 65%&lt;/P&gt;&lt;P&gt;...&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;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ..&lt;/P&gt;&lt;P&gt;Z&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 80%&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 90%&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I would like is the above but also a grand total at the bottom without necessarily doing the code twice, one with grouping, one without.&lt;/P&gt;&lt;P&gt;Thank you again for your time. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Best, &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lawrence &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 22:08:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61669#M13408</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-09-07T22:08:58Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61670#M13409</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;One possibility would be to use the create table statement in sql, rather than printing the results, and then use proc print with a summary line (e.g., &lt;A href="http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002262174.htm"&gt;http://support.sas.com/documentation/cdl/en/proc/61895/HTML/default/viewer.htm#a002262174.htm&lt;/A&gt; )&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;That would only require one pass thru the data, one pass thru the summaries, and very little extra coding.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 22:17:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61670#M13409</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-09-07T22:17:18Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61671#M13410</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Depending on your data structure consider using proc means with the Class Statement.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;It looks like your variables are indicators (ie 1, or 0) so the mean or average is the same as calculating a percentage. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc means data= MRSA_ADM_ARR noprint;&lt;/P&gt;&lt;P&gt;class mrsa_class;&lt;/P&gt;&lt;P&gt;var com test;&lt;/P&gt;&lt;P&gt;output out=sample_data mean=/autoname;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Your output will contain a _TYPE_ variable, the type 0 is your overall and Type1 is your individual summary. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 22:45:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61671#M13410</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2011-09-07T22:45:40Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61672#M13411</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;To Art &amp;amp; Reeza-&lt;/P&gt;&lt;P&gt;Thanks for your helpful answers.&lt;/P&gt;&lt;P&gt;@Reeza-I am well acquainted with proc means but was looking for an answer in SQL, which I believe there is none that is suitable at the moment.&lt;/P&gt;&lt;P&gt;Proc Means it is!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lawrence&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Sep 2011 22:49:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61672#M13411</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-09-07T22:49:56Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61673#M13412</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Is this what you're looking for:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG&gt;&lt;SPAN lang="EN-US" style="color: navy; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;proc &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: navy; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;sql&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;select&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a.&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;*&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; sashelp.class &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;as &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;a&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;OUTER&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;UNION&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; CORRESPONDING &lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;select&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="color: purple; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;'* TOTAL AGE *'&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;as &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;name, sum(age) &lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;as&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; age&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;from&lt;/SPAN&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; sashelp.class&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;group&lt;/SPAN&gt; &lt;SPAN lang="EN-US" style="color: blue; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;by&lt;/SPAN&gt; &lt;STRONG&gt;&lt;SPAN lang="EN-US" style="color: teal; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;1&lt;/SPAN&gt;&lt;/STRONG&gt;&lt;SPAN lang="EN-US" style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;STRONG style="color: navy; font-size: 10pt; background-color: white; font-family: 'Courier New';"&gt;quit&lt;/STRONG&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P style="margin-bottom: 0.0001pt;"&gt;&lt;SPAN style="color: black; background-color: white; font-family: 'Courier New'; font-size: 10pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Sep 2011 09:58:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61673#M13412</guid>
      <dc:creator>Hobbes</dc:creator>
      <dc:date>2011-09-08T09:58:11Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61674#M13413</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hobbes-&lt;/P&gt;&lt;P&gt;I had to modify the query a tiny bit for the outcome but it works! Thank you!&lt;/P&gt;&lt;P&gt;Lawrence&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Sep 2011 15:49:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61674#M13413</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-09-08T15:49:16Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61675#M13414</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Just FWIW, while the solution Hobbes proposed will get you the desired result, it involves two passes through your data.&amp;nbsp; If your file isn't very large, that definitely requires the least coding (though not by much).&amp;nbsp; If your dataset is fairly large, though, I would still recommend a two-step approach (like combining proc sql with proc print) as the proc print portion would only need to read through the much smaller summarized file.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Sep 2011 16:05:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61675#M13414</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2011-09-08T16:05:12Z</dc:date>
    </item>
    <item>
      <title>PROC SQL, group by &amp; total</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61676#M13415</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Art, &lt;/P&gt;&lt;P&gt;In the case, the data set isn't that big but duly noted on larger data sets in the future.&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Lawrence &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Sep 2011 16:09:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SQL-group-by-total/m-p/61676#M13415</guid>
      <dc:creator>_LB</dc:creator>
      <dc:date>2011-09-08T16:09:11Z</dc:date>
    </item>
  </channel>
</rss>

