<?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: How to add total row at bottom of table by group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872341#M344641</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, the question is how to obtain the report shown based on the dataset have (specifically how to add that final row with Totals at the bottom). Thanks!&lt;/P&gt;</description>
    <pubDate>Wed, 26 Apr 2023 18:56:51 GMT</pubDate>
    <dc:creator>Merdock</dc:creator>
    <dc:date>2023-04-26T18:56:51Z</dc:date>
    <item>
      <title>How to add total row at bottom of table by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872333#M344637</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following dataset and I was wondering how can I add a row at the bottom with the totals?&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input VISIT SITE$ N EXPCT OCCRD PERCENT OCCPCT$;
datalines;
1	AAA	11	10	7	70	7(70%)
2	AAA	11	0	0	0	0(0%)
1	BBB	14	5	5	100	5(100%)
2	BBB	14	4	2	50	2(50%)
1	CCC	80	46	39	84.783	39(84.8%)
2	CCC	80	0	0	0	0(0%)
;
run;
proc print data=have; run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I want my final output (in Word) to look like this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Merdock_0-1682532097818.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/83262iE8C25E8C6EAD15A2/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Merdock_0-1682532097818.png" alt="Merdock_0-1682532097818.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Where the percentage in the Total row comes from division by the Total Site N so: 48.6%=51/105, and 1.9%=2/105.&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 18:03:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872333#M344637</guid>
      <dc:creator>Merdock</dc:creator>
      <dc:date>2023-04-26T18:03:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to add total row at bottom of table by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872340#M344640</link>
      <description>&lt;P&gt;Is your question:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to produce the report shown?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Or, is it as you have stated, how to produce a data set that looks somewhat like the report? (If so, why?)&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 18:51:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872340#M344640</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-26T18:51:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to add total row at bottom of table by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872341#M344641</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;, the question is how to obtain the report shown based on the dataset have (specifically how to add that final row with Totals at the bottom). Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 18:56:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872341#M344641</guid>
      <dc:creator>Merdock</dc:creator>
      <dc:date>2023-04-26T18:56:51Z</dc:date>
    </item>
    <item>
      <title>Re: How to add total row at bottom of table by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872344#M344643</link>
      <description>&lt;P&gt;This should work. I consider something like the text string 7(70%) to be such a poor way to display data that I haven't programmed it. Of course, you can program it if you'd like. I have also fixed a spelling error.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=have nway;
    class visit;
    var n expct occrd;
    output out=_stats_ sum=;
run;

data have1;
    length site $ 5;
    set have _stats_(drop=_:);
    if missing(site) then site='Total';
    if site='Total' then percent=occrd/n;
    else percent=percent/100;
run;

proc report data=have1;
    columns site n visit,(occrd percent expct);
    define site/group "Site" order=data;
    define n/group "N";
    define visit/across "Yearly Visits";
    define occrd/sum "Total Occurred";
    define percent/sum "Percent" format=percent8.1;
    define expct/sum "Total Expected";
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Apr 2023 19:14:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872344#M344643</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-26T19:14:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to add total row at bottom of table by group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872386#M344668</link>
      <description>this works perfectly, thank you so much!</description>
      <pubDate>Wed, 26 Apr 2023 20:58:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-add-total-row-at-bottom-of-table-by-group/m-p/872386#M344668</guid>
      <dc:creator>Merdock</dc:creator>
      <dc:date>2023-04-26T20:58:02Z</dc:date>
    </item>
  </channel>
</rss>

