<?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-Control columns order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-Control-columns-order/m-p/522430#M141831</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am running proc tabulate to create a summary report.&lt;/P&gt;
&lt;P&gt;I want to ask how can I control the order of the columns in the summary report.(for example: By total sales)&lt;/P&gt;
&lt;P&gt;I want that the Region with highest total sales will appear first.&lt;/P&gt;
&lt;P&gt;So we need to see following order of columns:&lt;/P&gt;
&lt;P&gt;Middle East &amp;nbsp; 5,631,779&lt;/P&gt;
&lt;P&gt;United States &amp;nbsp;&amp;nbsp;5,503,986&lt;/P&gt;
&lt;P&gt;Western Europe &amp;nbsp;4,873,000&lt;/P&gt;
&lt;P&gt;Canada &amp;nbsp;4,255,712&lt;/P&gt;
&lt;P&gt;Central America/Caribbean 3,657,753&lt;/P&gt;
&lt;P&gt;South America &amp;nbsp;2,434,783&lt;/P&gt;
&lt;P&gt;Eastern Europe &amp;nbsp;2,394,940&lt;/P&gt;
&lt;P&gt;Africa &amp;nbsp; 2,342,588&lt;/P&gt;
&lt;P&gt;Pacific &amp;nbsp; 2,296,794&lt;/P&gt;
&lt;P&gt;Asia &amp;nbsp; 460,231&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=sashelp.shoes f=comma18.;
  var sales inventory returns;
  class region;
  table sales*sum  inventory*mean  returns*max, region all;
run;&lt;/CODE&gt;&lt;/PRE&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>Wed, 19 Dec 2018 05:01:20 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2018-12-19T05:01:20Z</dc:date>
    <item>
      <title>proc tabulate-Control columns order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-Control-columns-order/m-p/522430#M141831</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I am running proc tabulate to create a summary report.&lt;/P&gt;
&lt;P&gt;I want to ask how can I control the order of the columns in the summary report.(for example: By total sales)&lt;/P&gt;
&lt;P&gt;I want that the Region with highest total sales will appear first.&lt;/P&gt;
&lt;P&gt;So we need to see following order of columns:&lt;/P&gt;
&lt;P&gt;Middle East &amp;nbsp; 5,631,779&lt;/P&gt;
&lt;P&gt;United States &amp;nbsp;&amp;nbsp;5,503,986&lt;/P&gt;
&lt;P&gt;Western Europe &amp;nbsp;4,873,000&lt;/P&gt;
&lt;P&gt;Canada &amp;nbsp;4,255,712&lt;/P&gt;
&lt;P&gt;Central America/Caribbean 3,657,753&lt;/P&gt;
&lt;P&gt;South America &amp;nbsp;2,434,783&lt;/P&gt;
&lt;P&gt;Eastern Europe &amp;nbsp;2,394,940&lt;/P&gt;
&lt;P&gt;Africa &amp;nbsp; 2,342,588&lt;/P&gt;
&lt;P&gt;Pacific &amp;nbsp; 2,296,794&lt;/P&gt;
&lt;P&gt;Asia &amp;nbsp; 460,231&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=sashelp.shoes f=comma18.;
  var sales inventory returns;
  class region;
  table sales*sum  inventory*mean  returns*max, region all;
run;&lt;/CODE&gt;&lt;/PRE&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>Wed, 19 Dec 2018 05:01:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-Control-columns-order/m-p/522430#M141831</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2018-12-19T05:01:20Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate-Control columns order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-Control-columns-order/m-p/522505#M141864</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Good question. It seems that, in general, without additional preparations all of the available settings of the ORDER= option of the CLASS statement establish different column orders.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, I think you'd need to make "additional preparations," for example create a format with the &lt;FONT face="courier new,courier"&gt;notsorted&lt;/FONT&gt; option, based on the properly sorted output dataset of a preliminary PROC TABULATE step, and use this format for the CLASS variable in question (REGION in your example) together with the options &lt;FONT face="courier new,courier"&gt;preloadfmt order=data&lt;/FONT&gt; of the CLASS statement in the final PROC TABULATE step, as shown below.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;ods select none;
proc tabulate data=sashelp.shoes out=_tmp(drop=_:);
var sales;
class region;
table sales*sum, region;
run;
ods select all;

proc sort data=_tmp;
by descending sales_sum;
run;

data _fmt;
retain fmtname '$_tmpfmt' hlo 'S';
set _tmp(rename=(region=start));
label=start;
run;

proc format cntlin=_fmt;
run;

proc tabulate data=sashelp.shoes f=comma18.;
var sales inventory returns;
format region $_tmpfmt.;
class region / preloadfmt order=data;
table sales*sum inventory*mean returns*max, region all;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Note that in spite of "&lt;FONT face="courier new,courier"&gt;order=data&lt;/FONT&gt;" there is no need to sort or modify the input dataset in any way.&lt;/P&gt;</description>
      <pubDate>Wed, 19 Dec 2018 13:19:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-Control-columns-order/m-p/522505#M141864</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-12-19T13:19:32Z</dc:date>
    </item>
  </channel>
</rss>

