<?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-N SUM PCTN PCTSUM-order of rows in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/589912#M168792</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have raw data that contain 3 columns: customer ID, score, obligation.&lt;/P&gt;
&lt;P&gt;I need to create the following summary table:&lt;/P&gt;
&lt;P&gt;Class variable: Score&amp;nbsp; (categories will be defined by proc format)&lt;/P&gt;
&lt;P&gt;Need to calculated:&lt;/P&gt;
&lt;P&gt;Number of customer of each category&lt;/P&gt;
&lt;P&gt;Sum of&amp;nbsp;obligation for each category&lt;/P&gt;
&lt;P&gt;%customers from Total customers for each category (without categories 13,14)&lt;/P&gt;
&lt;P&gt;%Total obligation&amp;nbsp; from Total obligation for each category (without categories 13,14)&lt;/P&gt;
&lt;P&gt;The problem is that in the output table the order of the rows (categories) is not as I wish.&lt;/P&gt;
&lt;P&gt;The order should be :&lt;/P&gt;
&lt;P&gt;'0'&lt;BR /&gt;'2--7'&lt;BR /&gt;'8'&lt;BR /&gt;'9--10'&lt;BR /&gt;'11'&lt;BR /&gt;'12'&lt;/P&gt;
&lt;P&gt;TOTAL 0-12&lt;BR /&gt;'13'&lt;BR /&gt;'14'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in this code the Total 0-12 appears in first row and also I need to change the name of this category from null (.) to&amp;nbsp;TOTAL 0-12&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rawtbl;
input ID score obligo;
cards;
1 0 10
2 0 12
3 4 14
4 3 16
5 3 18
6 8 20
7 8 22
8 8 24
9 11 26
10 9 28
11 12 30
12 11 32
13 13 34
14 14 36
15 14 38
;
run;


proc format ;
value ffmt
0='0'
2-7='2--7'
8='8'
9-10='9--10'
11='11'
12='12'
13='13'
14='14'
;
Run;


ods select none;
proc tabulate data=rawtbl f=comma18. out=summary1 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL, ID*N   obligo*sum  ;
format score ffmt.;
run;
ods select all;



ods select none;
proc tabulate data=rawtbl(where=(score between 0 and 12)) f=comma18. out=summary2 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL, ID*PCTN   obligo*PCTSUM  ;
format score ffmt.;
run;
ods select all;


proc sort data=summary1;by score;run;
proc sort data=summary2;by score;run;

Data Summary3;
Merge summary1(in=a) summary2(in=b);
by score;
Run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Thu, 19 Sep 2019 05:08:09 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-09-19T05:08:09Z</dc:date>
    <item>
      <title>PROC TABULATE-N SUM PCTN PCTSUM-order of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/589912#M168792</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have raw data that contain 3 columns: customer ID, score, obligation.&lt;/P&gt;
&lt;P&gt;I need to create the following summary table:&lt;/P&gt;
&lt;P&gt;Class variable: Score&amp;nbsp; (categories will be defined by proc format)&lt;/P&gt;
&lt;P&gt;Need to calculated:&lt;/P&gt;
&lt;P&gt;Number of customer of each category&lt;/P&gt;
&lt;P&gt;Sum of&amp;nbsp;obligation for each category&lt;/P&gt;
&lt;P&gt;%customers from Total customers for each category (without categories 13,14)&lt;/P&gt;
&lt;P&gt;%Total obligation&amp;nbsp; from Total obligation for each category (without categories 13,14)&lt;/P&gt;
&lt;P&gt;The problem is that in the output table the order of the rows (categories) is not as I wish.&lt;/P&gt;
&lt;P&gt;The order should be :&lt;/P&gt;
&lt;P&gt;'0'&lt;BR /&gt;'2--7'&lt;BR /&gt;'8'&lt;BR /&gt;'9--10'&lt;BR /&gt;'11'&lt;BR /&gt;'12'&lt;/P&gt;
&lt;P&gt;TOTAL 0-12&lt;BR /&gt;'13'&lt;BR /&gt;'14'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in this code the Total 0-12 appears in first row and also I need to change the name of this category from null (.) to&amp;nbsp;TOTAL 0-12&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rawtbl;
input ID score obligo;
cards;
1 0 10
2 0 12
3 4 14
4 3 16
5 3 18
6 8 20
7 8 22
8 8 24
9 11 26
10 9 28
11 12 30
12 11 32
13 13 34
14 14 36
15 14 38
;
run;


proc format ;
value ffmt
0='0'
2-7='2--7'
8='8'
9-10='9--10'
11='11'
12='12'
13='13'
14='14'
;
Run;


ods select none;
proc tabulate data=rawtbl f=comma18. out=summary1 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL, ID*N   obligo*sum  ;
format score ffmt.;
run;
ods select all;



ods select none;
proc tabulate data=rawtbl(where=(score between 0 and 12)) f=comma18. out=summary2 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL, ID*PCTN   obligo*PCTSUM  ;
format score ffmt.;
run;
ods select all;


proc sort data=summary1;by score;run;
proc sort data=summary2;by score;run;

Data Summary3;
Merge summary1(in=a) summary2(in=b);
by score;
Run;


&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 05:08:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/589912#M168792</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-09-19T05:08:09Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE-N SUM PCTN PCTSUM-order of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/589966#M168809</link>
      <description>&lt;P&gt;I run your code and the total was at the bottom of the table labeled as 'ALL'.&lt;/P&gt;
&lt;P&gt;You can change the label as in:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=rawtbl f=comma18. out=summary1 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL='Total', ID*N   obligo*sum  ;
format score ffmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you prefer to see the total on firs row then :&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=rawtbl f=comma18. out=summary1 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables ALL='Total' score , ID*N   obligo*sum  ;
format score ffmt.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 08:55:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/589966#M168809</guid>
      <dc:creator>Shmuel</dc:creator>
      <dc:date>2019-09-19T08:55:37Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE-N SUM PCTN PCTSUM-order of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/590047#M168836</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I have raw data that contain 3 columns: customer ID, score, obligation.&lt;/P&gt;
&lt;P&gt;I need to create the following summary table:&lt;/P&gt;
&lt;P&gt;Class variable: Score&amp;nbsp; (categories will be defined by proc format)&lt;/P&gt;
&lt;P&gt;Need to calculated:&lt;/P&gt;
&lt;P&gt;Number of customer of each category&lt;/P&gt;
&lt;P&gt;Sum of&amp;nbsp;obligation for each category&lt;/P&gt;
&lt;P&gt;%customers from Total customers for each category (without categories 13,14)&lt;/P&gt;
&lt;P&gt;%Total obligation&amp;nbsp; from Total obligation for each category (without categories 13,14)&lt;/P&gt;
&lt;P&gt;The problem is that in the output table the order of the rows (categories) is not as I wish.&lt;/P&gt;
&lt;P&gt;The order should be :&lt;/P&gt;
&lt;P&gt;'0'&lt;BR /&gt;'2--7'&lt;BR /&gt;'8'&lt;BR /&gt;'9--10'&lt;BR /&gt;'11'&lt;BR /&gt;'12'&lt;/P&gt;
&lt;P&gt;TOTAL 0-12&lt;BR /&gt;'13'&lt;BR /&gt;'14'&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But in this code the Total 0-12 appears in first row and also I need to change the name of this category from null (.) to&amp;nbsp;TOTAL 0-12&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data rawtbl;
input ID score obligo;
cards;
1 0 10
2 0 12
3 4 14
4 3 16
5 3 18
6 8 20
7 8 22
8 8 24
9 11 26
10 9 28
11 12 30
12 11 32
13 13 34
14 14 36
15 14 38
;
run;


proc format ;
value ffmt
0='0'
2-7='2--7'
8='8'
9-10='9--10'
11='11'
12='12'
13='13'
14='14'
;
Run;


ods select none;
proc tabulate data=rawtbl f=comma18. out=summary1 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL, ID*N   obligo*sum  ;
format score ffmt.;
run;
ods select all;



ods select none;
proc tabulate data=rawtbl(where=(score between 0 and 12)) f=comma18. out=summary2 (drop=_type_ _page_ _table_) ;
class score ;
var obligo  ID;
tables score ALL, ID*PCTN   obligo*PCTSUM  ;
format score ffmt.;
run;
ods select all;


proc sort data=summary1;by score;run;
proc sort data=summary2;by score;run;

Data Summary3;
Merge summary1(in=a) summary2(in=b);
by score;
Run;


&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Since you do not show what you actually expect&amp;nbsp; &lt;FONT size="4"&gt;&lt;STRONG&gt;&lt;FONT color="#339966"&gt;[HINT]&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/FONT&gt;&amp;nbsp;I am going to guess that maybe what you&amp;nbsp; want is something like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;proc format library=work;
value ffmt (multilabel notsorted)
0='0'
2-7='2--7'
8='8'
9-10='9--10'
11='11'
12='12'
0 - 12 = 'Total 0-12'
13='13'
14='14'
;
Run;

proc sort data=work.rawtbl;
  by score;
run;

proc tabulate data=work.rawtbl f=comma18. out=summary1 (drop=_type_ _page_ _table_) ;
class score /mlf order=data preloadfmt;
var obligo  ID;
tables score , ID*N   obligo*sum  ;
format score ffmt.;
run;&lt;/PRE&gt;</description>
      <pubDate>Thu, 19 Sep 2019 14:50:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/590047#M168836</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-09-19T14:50:39Z</dc:date>
    </item>
    <item>
      <title>Re: PROC TABULATE-N SUM PCTN PCTSUM-order of rows</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/591953#M169674</link>
      <description>&lt;P&gt;Sorry fort late response and thank you.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to calculate following 4 statistics:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;a- SUM of obligation for following categories: 0 ,2-7,8,9-10,11,12,0-12,13,14&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;b-Number of customers for following categories: 0 ,2-7,8,9-10,11,12,0-12,13,14&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;c-Percent of&amp;nbsp;SUM of obligation&amp;nbsp; from total&amp;nbsp;for following categories: 0 ,2-7,8,9-10,11,12,0-12 (without 13,14 ).&lt;/P&gt;
&lt;P&gt;As you understand for calculation c the total obligation will be calculated from categories 0-12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;d-Percent of&amp;nbsp;number of customers&amp;nbsp; from total&amp;nbsp;for following categories: 0 ,2-7,8,9-10,11,12,0-12 (without 13,14 ).&lt;/P&gt;
&lt;P&gt;As you understand for calculation d the total of customers will be calculated from categories 0-12&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note:&lt;/P&gt;
&lt;P&gt;In the output I want to see the categories in the following logic order&lt;/P&gt;
&lt;P&gt;0 ,2-7,8,9-10,11,12,0-12,13,14&lt;/P&gt;
&lt;P&gt;I want to dispaly also categories with summary statistics value 0&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;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Sep 2019 18:41:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-TABULATE-N-SUM-PCTN-PCTSUM-order-of-rows/m-p/591953#M169674</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-09-26T18:41:59Z</dc:date>
    </item>
  </channel>
</rss>

