<?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: Row and bottomline percentage average for proc tabulate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Row-and-bottomline-percentage-average-for-proc-tabulate/m-p/744273#M233159</link>
    <description>&lt;P&gt;Perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data= baseball;
   class Team;
   var nAtBat
   	nHits ;
   Table Team =' ' all='Grand Total' ,
   nAtBat*(sum*f=comma15.) nHits*(sum*f=comma15.  pctsum&amp;lt;natbat&amp;gt;)

   ;
   label nAtBat = 'Total At Bats';
   label nHits = 'Total Hits';
   
run;&lt;/PRE&gt;
&lt;P&gt;You can provide another variable in the table and use Pctsum&amp;lt;variable&amp;gt; or Pctn&amp;lt;variable&amp;gt; to provide the sum or count of the the other variable as the denominator for percent calculations. There are restrictions about where these can go in relation to specific table structure. The &amp;lt;&amp;gt; characters are required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the question is how to calculate something please don't include a bunch of extra "style" elements that obscure the details of the question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW there really isn't a need to create a data set for that simple subset of the data. You could use a where statement in Proc tabulate like&lt;/P&gt;
&lt;PRE&gt;where team in ('Cleveland','Houston','Seattle','Montreal');&lt;/PRE&gt;
&lt;P&gt;with the sashelp.baseball as the data set in the Proc Tabulate statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 27 May 2021 19:16:14 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2021-05-27T19:16:14Z</dc:date>
    <item>
      <title>Row and bottomline percentage average for proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Row-and-bottomline-percentage-average-for-proc-tabulate/m-p/744259#M233149</link>
      <description>&lt;PRE&gt;data baseball(keep=Team nAtBat nHits);
set sashelp.baseball;
if team in ('Cleveland','Houston','Seattle','Montreal');
run;

proc tabulate data= baseball;
class Team;
var nAtBat
	nHits ;
Table Team =' ' all={label='Grand Total' 
S=[background = lightblue cellwidth=80]} 
*[STYLE=[Font_Weight=BOLD]],
nAtBat*(sum*f=comma15.)
nHits*(sum*f=comma15.);
label nAtBat = 'Total At Bats';
label nHits = 'Total Hits';
;run;&lt;/PRE&gt;
&lt;P&gt;The proc tabulate prouduces the following.&amp;nbsp; The objective is to get the percentage of hits to at bats and the bottomline average&lt;/P&gt;
&lt;TABLE width="412"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="121"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82"&gt;Total At Bats&lt;/TD&gt;
&lt;TD width="93"&gt;Total Hits&lt;/TD&gt;
&lt;TD width="116"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82"&gt;Sum&lt;/TD&gt;
&lt;TD width="93"&gt;Sum&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Cleveland&lt;/TD&gt;
&lt;TD&gt;5,478&lt;/TD&gt;
&lt;TD&gt;1,564&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Houston&lt;/TD&gt;
&lt;TD&gt;4,386&lt;/TD&gt;
&lt;TD&gt;1,201&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Montreal&lt;/TD&gt;
&lt;TD&gt;4,539&lt;/TD&gt;
&lt;TD&gt;1,216&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Seattle&lt;/TD&gt;
&lt;TD&gt;4,975&lt;/TD&gt;
&lt;TD&gt;1,279&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Grand Total&lt;/TD&gt;
&lt;TD&gt;19,378&lt;/TD&gt;
&lt;TD&gt;5,260&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD colspan="4"&gt;Desire to get the percentage of the total at bats&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD rowspan="2" width="121"&gt;&amp;nbsp;&lt;/TD&gt;
&lt;TD width="82"&gt;Total At Bats&lt;/TD&gt;
&lt;TD width="93"&gt;Total Hits&lt;/TD&gt;
&lt;TD&gt;Pct Hits to At bats&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="82"&gt;Sum&lt;/TD&gt;
&lt;TD width="93"&gt;Sum&lt;/TD&gt;
&lt;TD&gt;&amp;nbsp;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Cleveland&lt;/TD&gt;
&lt;TD&gt;5,478&lt;/TD&gt;
&lt;TD&gt;1,564&lt;/TD&gt;
&lt;TD&gt;28.55%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Houston&lt;/TD&gt;
&lt;TD&gt;4,386&lt;/TD&gt;
&lt;TD&gt;1,201&lt;/TD&gt;
&lt;TD&gt;27.38%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Montreal&lt;/TD&gt;
&lt;TD&gt;4,539&lt;/TD&gt;
&lt;TD&gt;1,216&lt;/TD&gt;
&lt;TD&gt;26.79%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Seattle&lt;/TD&gt;
&lt;TD&gt;4,975&lt;/TD&gt;
&lt;TD&gt;1,279&lt;/TD&gt;
&lt;TD&gt;25.71%&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="121"&gt;Grand Total&lt;/TD&gt;
&lt;TD&gt;19,378&lt;/TD&gt;
&lt;TD&gt;5,260&lt;/TD&gt;
&lt;TD&gt;27.14%&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 27 May 2021 18:16:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Row-and-bottomline-percentage-average-for-proc-tabulate/m-p/744259#M233149</guid>
      <dc:creator>Q1983</dc:creator>
      <dc:date>2021-05-27T18:16:11Z</dc:date>
    </item>
    <item>
      <title>Re: Row and bottomline percentage average for proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Row-and-bottomline-percentage-average-for-proc-tabulate/m-p/744273#M233159</link>
      <description>&lt;P&gt;Perhaps:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc tabulate data= baseball;
   class Team;
   var nAtBat
   	nHits ;
   Table Team =' ' all='Grand Total' ,
   nAtBat*(sum*f=comma15.) nHits*(sum*f=comma15.  pctsum&amp;lt;natbat&amp;gt;)

   ;
   label nAtBat = 'Total At Bats';
   label nHits = 'Total Hits';
   
run;&lt;/PRE&gt;
&lt;P&gt;You can provide another variable in the table and use Pctsum&amp;lt;variable&amp;gt; or Pctn&amp;lt;variable&amp;gt; to provide the sum or count of the the other variable as the denominator for percent calculations. There are restrictions about where these can go in relation to specific table structure. The &amp;lt;&amp;gt; characters are required.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When the question is how to calculate something please don't include a bunch of extra "style" elements that obscure the details of the question.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;BTW there really isn't a need to create a data set for that simple subset of the data. You could use a where statement in Proc tabulate like&lt;/P&gt;
&lt;PRE&gt;where team in ('Cleveland','Houston','Seattle','Montreal');&lt;/PRE&gt;
&lt;P&gt;with the sashelp.baseball as the data set in the Proc Tabulate statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 19:16:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Row-and-bottomline-percentage-average-for-proc-tabulate/m-p/744273#M233159</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-05-27T19:16:14Z</dc:date>
    </item>
  </channel>
</rss>

