<?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: proc tabulate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481039#M124379</link>
    <description>&lt;P&gt;You can use Proc TABULATE&amp;nbsp;for this. It allows to have the statistics on the row dimension, see the example below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code also creates two percent formats so that the numbers are displayed as percentages.&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;proc format;
  picture pct2fmt (round)
  low - &amp;lt; 0  = "099.99%"(prefix='-' )
  0          = "n/a"
  0 - high   = "099.99%"          
  ;

	picture pct1fmt (round)
	low - &amp;lt; 0  = "099.9%"(prefix='-' )
  0          = "n/a"
  0 - high   = "099.9%"          
  ;
run;


proc tabulate data=sashelp.class ;
  class age sex;
  var weight;
  table
    age*sum all*(sum pctsum*f=pct2fmt.)
    ,
    sex*weight all*weight
    / 
    
    row=float
  ;
  keylabel sum= " " pctsum=" ";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use Proc REPORT, you need to add additional variables so that you can have multiple breaklines. The _BREAK_ variable lets you know in which breakline you are and then fill the cells accordingly. Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class;
  break1 = 1;
  break2 = 1;
run;

%let doNotPrint = noprint;
/*%let doNotPrint = ;*/

Proc report data=class nowd;
  columns break1 break2 age sex,(weight=weightsum) weight=TotalSum _dummy;
  define break1 / group &amp;amp;doNotPrint;
  define break2 / group &amp;amp;doNotPrint;
  define age / group;
  define weight / sum;
  define sex / across 'sex'  order=formatted;
  define weightsum / sum  format=comma12.;
  define TotalSum / sum format=comma12. 'All sex';
  define _dummy / computed &amp;amp;doNotPrint;

  compute _dummy / char length=32;
    _dummy = catx(":", _break_, _c4_, _c5_, totalSum);
    if lowcase(_break_) = "break1" then do;
      _c4_ = _c4_ / TotalSum;
      _c5_ = _c5_ / TotalSum;
      TotalSum = TotalSum / TotalSum;
      call define("_c4_", "format", "percent9.2");
      call define("_c5_", "format", "percent9.2");
      call define("totalSum", "format", "percent9.2");
    end;

  endcomp;

  break after break1 / summarize;
  break after break2 / summarize;
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>Wed, 25 Jul 2018 07:43:45 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2018-07-25T07:43:45Z</dc:date>
    <item>
      <title>proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481024#M124369</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;Please see following code.&lt;/P&gt;&lt;P&gt;I need to create one more row in the output with percent of each column's total from grand total.&lt;/P&gt;&lt;P&gt;811/1901=43%&lt;/P&gt;&lt;P&gt;1090/1901=57%&lt;/P&gt;&lt;P&gt;1901/1901=100%&lt;/P&gt;&lt;P&gt;I guess that we cannot do it with proc report.&lt;/P&gt;&lt;P&gt;Can anyone show another way to do it with proc tabulate?&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;Proc report data=sashelp.class nowd;
   columns age sex,(weight=weightsum) weight=TotalSum;
   define age/ group   ;
   define weight / sum;
   define sex/across 'sex'  order=formatted ;
   define weightsum / sum  format=comma12.  ;
   define TotalSum / sum format=comma12. 'All sex';
rbreak after/ summarize;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jul 2018 06:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481024#M124369</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-07-25T06:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481039#M124379</link>
      <description>&lt;P&gt;You can use Proc TABULATE&amp;nbsp;for this. It allows to have the statistics on the row dimension, see the example below.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The code also creates two percent formats so that the numbers are displayed as percentages.&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;proc format;
  picture pct2fmt (round)
  low - &amp;lt; 0  = "099.99%"(prefix='-' )
  0          = "n/a"
  0 - high   = "099.99%"          
  ;

	picture pct1fmt (round)
	low - &amp;lt; 0  = "099.9%"(prefix='-' )
  0          = "n/a"
  0 - high   = "099.9%"          
  ;
run;


proc tabulate data=sashelp.class ;
  class age sex;
  var weight;
  table
    age*sum all*(sum pctsum*f=pct2fmt.)
    ,
    sex*weight all*weight
    / 
    
    row=float
  ;
  keylabel sum= " " pctsum=" ";
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can also use Proc REPORT, you need to add additional variables so that you can have multiple breaklines. The _BREAK_ variable lets you know in which breakline you are and then fill the cells accordingly. Here is an example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data class;
  set sashelp.class;
  break1 = 1;
  break2 = 1;
run;

%let doNotPrint = noprint;
/*%let doNotPrint = ;*/

Proc report data=class nowd;
  columns break1 break2 age sex,(weight=weightsum) weight=TotalSum _dummy;
  define break1 / group &amp;amp;doNotPrint;
  define break2 / group &amp;amp;doNotPrint;
  define age / group;
  define weight / sum;
  define sex / across 'sex'  order=formatted;
  define weightsum / sum  format=comma12.;
  define TotalSum / sum format=comma12. 'All sex';
  define _dummy / computed &amp;amp;doNotPrint;

  compute _dummy / char length=32;
    _dummy = catx(":", _break_, _c4_, _c5_, totalSum);
    if lowcase(_break_) = "break1" then do;
      _c4_ = _c4_ / TotalSum;
      _c5_ = _c5_ / TotalSum;
      TotalSum = TotalSum / TotalSum;
      call define("_c4_", "format", "percent9.2");
      call define("_c5_", "format", "percent9.2");
      call define("totalSum", "format", "percent9.2");
    end;

  endcomp;

  break after break1 / summarize;
  break after break2 / summarize;
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>Wed, 25 Jul 2018 07:43:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481039#M124379</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-07-25T07:43:45Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481054#M124385</link>
      <description>&lt;P&gt;It is perfect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I used this code that you showed.&lt;/P&gt;&lt;P&gt;Currently the extra row with percents is working for all age values .&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to &amp;nbsp;calculate the extra row (with percent calculations) that will apply only for ages 12-15.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;                           
   picture mypct (round) low-high='009.99%';   
run;
proc tabulate data=sashelp.class ;
  class age sex;
  var weight;
  table
    age*N all*(N pctsum*f=mypct.)
    ,
    sex*weight all*weight
    / 
    row=float
  ;
  keylabel N= " " pctsum=" ";
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 25 Jul 2018 08:53:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481054#M124385</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-07-25T08:53:42Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481062#M124391</link>
      <description>&lt;P&gt;So the table should show all the ages 11-16, but the percent calculation should only by done for ages 12-15, is this correct?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can you explain in more detail why it should be like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 25 Jul 2018 09:22:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate/m-p/481062#M124391</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2018-07-25T09:22:22Z</dc:date>
    </item>
  </channel>
</rss>

