<?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: 2 dimensional table with control of the order of categories in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615695#M180113</link>
    <description>&lt;P&gt;Use formats to create new variables with ordinal values. Run PROC TABULATE and decode the ordinal values back to original.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue field_code
   'max'   = 1
   'S_Max' = 2
   ;
invalue factor_code
   '1.2' = 1
   '1.1' = 2
   '1'   = 3
   ;
invalue Amnt_code
   ' '     = 1
   '50000' = 2
   '20000' = 3
   ;
invalue PCT_code
   ' '  = 1
   '50' = 2 
   '40' = 3
   '30' = 4
   ;

value field_decode
   1 = 'max'
   2 = 'S_Max'
   ;
value factor_decode
   1 = 1.2
   2 = 1.1
   3 = 1
   ;
value Amnt_decode
   1 = .
   2 = 50000
   3 = 20000
   ;
value PCT_decode
   1 = .
   2 = 50
   3 = 40
   4 = 30
   ;
run;

data tbl2;
   set tbl;
   field_code=input(field,field_code.);
   factor_code=input(strip(put(factor,best.)),factor_code.);
   Amnt_code=input(strip(put(Amnt,best.)),Amnt_code.);
   PCT_code=input(strip(put(PCT,best.)),PCT_code.);
run;
proc tabulate data=tbl2 ;
	class Amnt_code PCT_code field_code factor_code / missing;
	var Reduce;
	tables (Amnt_code*(PCT_code='' all='Total')),(field_code*(factor_code='' all='Total'))*(Reduce*mean);
   format field_code field_decode. factor_code factor_decode. Amnt_code Amnt_decode. PCT_code PCT_decode.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Edit:add totals&lt;/P&gt;</description>
    <pubDate>Wed, 08 Jan 2020 09:27:02 GMT</pubDate>
    <dc:creator>Oligolas</dc:creator>
    <dc:date>2020-01-08T09:27:02Z</dc:date>
    <item>
      <title>2 dimensional table with control of the order of categories</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615590#M180064</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am using proc tabulate for 2 dimensional table.&lt;/P&gt;
&lt;P&gt;The problem is that the order of the categorical values is not as I wish.&lt;/P&gt;
&lt;P&gt;The required orders of the categories are:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;order of "fileld"&amp;nbsp; &amp;nbsp; : max ,S_Max&lt;BR /&gt;order of "factor " : 1.2,1.1,1.0&lt;BR /&gt;order of "Amnt"&amp;nbsp; : Null,50000,20000&lt;BR /&gt;PCT order: Null,50,40,30&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What is the way to do it please?&lt;/P&gt;
&lt;P&gt;I also want to add extra&amp;nbsp; row of totals&lt;/P&gt;
&lt;P&gt;I also want to add extra&amp;nbsp; column of totals&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 tbl;
INFILE DATALINES DLM=',';
input field $ PCT Amnt   Factor	Reduce ;
cards;
max,.,.,1,-4490
max,30,20000,1,-2461
max,40,20000,1,-2981
max,50,20000,1,-3433
max,30,50000,1,-3621
max,40,50000,1,-3843
max,50,50000,1,-4039
max,.,.,1.1,-4157
max,30,20000,1.1,-2306
max,40,20000,1.1,-2788
max,50,20000,1.1,-3202
max,30,50000,1.1,-3361
max,40,50000,1.1,-3568
max,50,50000,1.1,-3749
max,.,.,1.2,-3858
max,30,20000,1.2,-2161
max,40,20000,1.2,-2607
max,50,20000,1.2,-2988
max,30,50000,1.2,-3125
max,40,50000,1.2,-3319
max,50,50000,1.2,-3486
S_Max,.,.,1,-5114
S_Max,30,20000,1,-2697
S_Max,40,20000,1,-3281
S_Max,50,20000,1,-3802
S_Max,30,50000,1,-4094
S_Max,40,50000,1,-4342
S_Max,50,50000,1,-4564
S_Max,.,.,1.1,-4804
S_Max,30,20000,1.1,-2573
S_Max,40,20000,1.1,-3122
S_Max,50,20000,1.1,-3606
S_Max,30,50000,1.1,-3859
S_Max,40,50000,1.1,-4093
S_Max,50,50000,1.1,-4301
S_Max,.,.,1.2,-4514
S_Max,30,20000,1.2,-2449
S_Max,40,20000,1.2,-2964
S_Max,50,20000,1.2,-3415
S_Max,30,50000,1.2,-3637
S_Max,40,50000,1.2,-3857
S_Max,50,50000,1.2,-4052
;
run;


proc tabulate data=tbl;
	class Amnt PCT field Factor / missing;
	var Reduce;
	tables (Amnt*PCT),(field*Factor)*(Reduce*mean) ;
run;
field order : max ,S_Max
factor order: 1.2,1.1,1.0
Amnt order:   Null,50000,20000
PCT order:    Null,50,40,30
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 07 Jan 2020 08:13:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615590#M180064</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2020-01-07T08:13:00Z</dc:date>
    </item>
    <item>
      <title>Re: 2 dimensional table with control of the order of categories</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615695#M180113</link>
      <description>&lt;P&gt;Use formats to create new variables with ordinal values. Run PROC TABULATE and decode the ordinal values back to original.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
invalue field_code
   'max'   = 1
   'S_Max' = 2
   ;
invalue factor_code
   '1.2' = 1
   '1.1' = 2
   '1'   = 3
   ;
invalue Amnt_code
   ' '     = 1
   '50000' = 2
   '20000' = 3
   ;
invalue PCT_code
   ' '  = 1
   '50' = 2 
   '40' = 3
   '30' = 4
   ;

value field_decode
   1 = 'max'
   2 = 'S_Max'
   ;
value factor_decode
   1 = 1.2
   2 = 1.1
   3 = 1
   ;
value Amnt_decode
   1 = .
   2 = 50000
   3 = 20000
   ;
value PCT_decode
   1 = .
   2 = 50
   3 = 40
   4 = 30
   ;
run;

data tbl2;
   set tbl;
   field_code=input(field,field_code.);
   factor_code=input(strip(put(factor,best.)),factor_code.);
   Amnt_code=input(strip(put(Amnt,best.)),Amnt_code.);
   PCT_code=input(strip(put(PCT,best.)),PCT_code.);
run;
proc tabulate data=tbl2 ;
	class Amnt_code PCT_code field_code factor_code / missing;
	var Reduce;
	tables (Amnt_code*(PCT_code='' all='Total')),(field_code*(factor_code='' all='Total'))*(Reduce*mean);
   format field_code field_decode. factor_code factor_decode. Amnt_code Amnt_decode. PCT_code PCT_decode.;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Edit:add totals&lt;/P&gt;</description>
      <pubDate>Wed, 08 Jan 2020 09:27:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615695#M180113</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2020-01-08T09:27:02Z</dc:date>
    </item>
    <item>
      <title>Re: 2 dimensional table with control of the order of categories</title>
      <link>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615718#M180125</link>
      <description />
      <pubDate>Tue, 07 Jan 2020 16:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/2-dimensional-table-with-control-of-the-order-of-categories/m-p/615718#M180125</guid>
      <dc:creator>1zmm</dc:creator>
      <dc:date>2020-01-07T16:27:42Z</dc:date>
    </item>
  </channel>
</rss>

