<?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 - order output by PCTSUM in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532511#M145924</link>
    <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In this proc tabulate table I want to order &amp;nbsp;by column PCTSUM&lt;/P&gt;
&lt;P&gt;The code is not working.&lt;/P&gt;
&lt;P&gt;How can I order output by&amp;nbsp;&lt;CODE class=" language-sas"&gt;PCTSUM?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=sashelp.cars;  
class Make/ORDER=PCTSUM;  
var Invoice;  
table Make='',Invoice=''*(n='Cars sold' PCTN='%Cars sold' SUM='Sum sales'  PCTSUM='PCT SUM sales')/box='Brand';
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 04 Feb 2019 06:58:07 GMT</pubDate>
    <dc:creator>Ronein</dc:creator>
    <dc:date>2019-02-04T06:58:07Z</dc:date>
    <item>
      <title>proc tabulate - order output by PCTSUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532511#M145924</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;In this proc tabulate table I want to order &amp;nbsp;by column PCTSUM&lt;/P&gt;
&lt;P&gt;The code is not working.&lt;/P&gt;
&lt;P&gt;How can I order output by&amp;nbsp;&lt;CODE class=" language-sas"&gt;PCTSUM?&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc tabulate data=sashelp.cars;  
class Make/ORDER=PCTSUM;  
var Invoice;  
table Make='',Invoice=''*(n='Cars sold' PCTN='%Cars sold' SUM='Sum sales'  PCTSUM='PCT SUM sales')/box='Brand';
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 04 Feb 2019 06:58:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532511#M145924</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2019-02-04T06:58:07Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate - order output by PCTSUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532533#M145933</link>
      <description>&lt;P&gt;Have a look at the documentation: the option "order" is defined as&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;ORDER=DATA | FORMATTED | FREQ | UNFORMATTED&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So there is no way to specify pctsum as sort-order.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 11:19:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532533#M145933</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2019-02-04T11:19:15Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate - order output by PCTSUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532573#M145943</link>
      <description>&lt;P&gt;You can't order by PCTSUM, but as &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp; notes you&amp;nbsp; can order by data (i.e. in order of the data&amp;nbsp; set).&amp;nbsp; So you could&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;Run proc summary to do the aggregation work, and write the totals to data set NEED&lt;/LI&gt;
&lt;LI&gt;Sort NEED by sum of invoices (or descending sum of invoices)&lt;/LI&gt;
&lt;LI&gt;Run proc tabulate against data set need, using order=data.&lt;/LI&gt;
&lt;/OL&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc summary data=sashelp.cars;
  class make;
  var invoice;
  output out=need (where=(_type_=1)) mean=invoice sum=invtotal;
run;
proc sort;by descending invtotal;run;

proc tabulate data=need  order=data;
  class make;
  var invoice;
  freq _freq_;
  table Make='',Invoice=''*(n='Cars sold' PCTN='%Cars sold' SUM='Sum sales'  PCTSUM='PCT SUM sales')/box='Brand';
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL style="list-style-position: inside;"&gt;
&lt;LI&gt;The "where = (_type_=1)" option in the proc summary tells sas to only output the 1-way frequencies and sums.&amp;nbsp; Otherwise it would also include a single output record with total frequency and overall sum (_TYPE_=0).&amp;nbsp; &lt;BR /&gt;edited addition:&amp;nbsp; proc summary also creates the automatic variables _FREQ_ which give number of observations contributing to the aggregate record.&lt;/LI&gt;
&lt;LI&gt;The first proc generates the INVTOTAL for sorting, and the MEAN=INVOICE to use as an analysis variable after sorting.&lt;/LI&gt;
&lt;LI&gt;The second proc tabulate uses the "order=data" option.&amp;nbsp; The statement "FREQ _FREQ_;"&amp;nbsp; tells sas to treat the observations in data set need as weighted observations.&lt;BR /&gt;edited addition:&amp;nbsp; _FREQ_ is the automatic variable created in step 1.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Mon, 04 Feb 2019 16:27:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532573#M145943</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-02-04T16:27:21Z</dc:date>
    </item>
    <item>
      <title>Re: proc tabulate - order output by PCTSUM</title>
      <link>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532607#M145953</link>
      <description>&lt;P&gt;Or in a modification of &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; use one pass through proc tabulate to create an output data set then a data step for some modification and then sort. You may use proc tabulate but with pre-calculated statistics you need to be careful not to ask for pcts or sums again. Or use proc report list output.&lt;/P&gt;</description>
      <pubDate>Mon, 04 Feb 2019 16:10:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/proc-tabulate-order-output-by-PCTSUM/m-p/532607#M145953</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-02-04T16:10:24Z</dc:date>
    </item>
  </channel>
</rss>

