<?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 tabulate -percent from total column per each group in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724837#M225073</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate percent from total in each category.&lt;/P&gt;
&lt;P&gt;I want to create the following summary table.&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1615293743058.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55715i0864A114BD718645/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1615293743058.png" alt="Ronein_0-1615293743058.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;
Data Rawtbl;
input ID field $  category  year ;
cards;
1 x 1 2020 
1 w 2 2020
1 z 2 2020
2 x 2 2020
2 w 3 2020
2 z 2 2020
3 x 2 2020
3 w 2 2020
3 z 2 2020
4 x 1 2020
4 w 2 2020
4 z 1 2020
5 x 3 2020
5 w 2 2020
5 z 2 2020
6 x 2 2021 
6 w 3 2021
6 z 1 2021
2 x 1 2021
2 w 1 2021
2 z 1 2021
3 x 2 2021
3 w 2 2021
3 z 3 2021
4 x 3 2021
4 w 2 2021
4 z 1 2021
;
run;
PROC TABULATE DATA=Rawtbl OUT=ttt ;
CLASS  field category  year ;
VAR ID ; 
TABLE (field='')*(category='' ALL='Total'),year=''*N/misstext='0';
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 09 Mar 2021 12:43:07 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2021-03-09T12:43:07Z</dc:date>
    <item>
      <title>proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724837#M225073</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to calculate percent from total in each category.&lt;/P&gt;
&lt;P&gt;I want to create the following summary table.&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Ronein_0-1615293743058.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55715i0864A114BD718645/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Ronein_0-1615293743058.png" alt="Ronein_0-1615293743058.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&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;
Data Rawtbl;
input ID field $  category  year ;
cards;
1 x 1 2020 
1 w 2 2020
1 z 2 2020
2 x 2 2020
2 w 3 2020
2 z 2 2020
3 x 2 2020
3 w 2 2020
3 z 2 2020
4 x 1 2020
4 w 2 2020
4 z 1 2020
5 x 3 2020
5 w 2 2020
5 z 2 2020
6 x 2 2021 
6 w 3 2021
6 z 1 2021
2 x 1 2021
2 w 1 2021
2 z 1 2021
3 x 2 2021
3 w 2 2021
3 z 3 2021
4 x 3 2021
4 w 2 2021
4 z 1 2021
;
run;
PROC TABULATE DATA=Rawtbl OUT=ttt ;
CLASS  field category  year ;
VAR ID ; 
TABLE (field='')*(category='' ALL='Total'),year=''*N/misstext='0';
RUN;

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 12:43:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724837#M225073</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-09T12:43:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724845#M225074</link>
      <description>&lt;P&gt;If the columns have to be in that order Tabulate is not going to do that.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 13:11:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724845#M225074</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-03-09T13:11:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724897#M225084</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; The reason that TABULATE won't do the columns in that order is that you want the percents to be based on the category values in each field group and for that to happen, both category and field need to be in the row dimension in TABULATE. You can get THIS order to the columns:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1615304915566.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55737i14F6AB82148A9FBB/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1615304915566.png" alt="Cynthia_sas_0-1615304915566.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;But you can't get FIELD and CATEGORY on the far right the way you envision. To get the percent of the subgroup for each field, you need to use a custom denominator in TABULATE (if you can live with the column order).&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 15:50:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724897#M225084</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-03-09T15:50:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724965#M225108</link>
      <description>&lt;P&gt;May anyone show another way to do it (Maybe via proc report )?&lt;/P&gt;</description>
      <pubDate>Tue, 09 Mar 2021 20:12:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/724965#M225108</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-09T20:12:31Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/725033#M225145</link>
      <description>Hi:&lt;BR /&gt;  PROC REPORT might be able to get you closer. You could take a first pass using TABULATE to get the percents calculated correctly, and then use PROC REPORT. But still the output won't look exactly as you envision. &lt;BR /&gt;Cynthia</description>
      <pubDate>Wed, 10 Mar 2021 02:53:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/725033#M225145</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-03-10T02:53:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/725059#M225161</link>
      <description>May you show the code pls?</description>
      <pubDate>Wed, 10 Mar 2021 06:00:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/725059#M225161</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-03-10T06:00:09Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate -percent from total column per each group</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/725144#M225200</link>
      <description>&lt;P&gt;Hi:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; I would probably use this approach. However, I think that while it comes close, it doesn't look as good as what you get from TABULATE.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Cynthia_sas_0-1615385136229.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/55765i32630720422B9843/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Cynthia_sas_0-1615385136229.png" alt="Cynthia_sas_0-1615385136229.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Note that because FIELD and CATEGORY moved (or were copied) to the right side of the table, the cell for field cannot span the cells for category as you show. PROC REPORT will not do that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cynthia&lt;/P&gt;</description>
      <pubDate>Wed, 10 Mar 2021 14:13:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-percent-from-total-column-per-each-group/m-p/725144#M225200</guid>
      <dc:creator>Cynthia_sas</dc:creator>
      <dc:date>2021-03-10T14:13:58Z</dc:date>
    </item>
  </channel>
</rss>

