<?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: Sorting a PROC tabulate by two variables? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433162#M281831</link>
    <description>&lt;P&gt;With proc tabulate you can provide different ORDER = option for each class variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;perhaps this will work for your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;class perm_city /order=data;&lt;/P&gt;
&lt;P&gt;class semester /order=unformatted;&lt;/P&gt;</description>
    <pubDate>Thu, 01 Feb 2018 16:20:03 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2018-02-01T16:20:03Z</dc:date>
    <item>
      <title>Sorting a PROC tabulate by two variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433136#M281830</link>
      <description>&lt;P&gt;How can I can I sort a table by two variables?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a table that starts as a PROC SQL to create the table and variables, moves through a DATA step to limit the range of data, and then into a PROC TABULATE to present the information. I ordered the data in descending order for my numeric variable in the PROC SQL step and passed that to my PROC TAB using ORDER=DATA. This works fine.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, in my PROC TAB I also need my top row of variables to be in order of semester (Fall 2015, Spring 2016, Summer 2017 etc.) with my numeric variable still in descending order. By default it sorts my top row alphabetically. I tried creating a PROC FORMAT and adding that to the PROC TAB but it doesn't work (code sample below). I've also tried some various combinations to no avail.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC FORMAT;&lt;BR /&gt;VALUE $term_order&lt;BR /&gt;'1' = 'Spring 2018'&lt;BR /&gt;'2' = 'Fall 2017'&lt;BR /&gt;'3' = 'Summer 2017'&lt;BR /&gt;'4' = 'Spring 2017'&lt;BR /&gt;'5' = 'Fall 2016';&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;PROC SQL;&lt;BR /&gt;CREATE TABLE top_cities AS SELECT *,count(perm_city) AS city_count FROM transform_1&lt;BR /&gt;GROUP BY perm_city ORDER BY city_count DESC;&lt;BR /&gt;quit;&lt;BR /&gt;&lt;BR /&gt;DATA top10_cities; SET top_cities;&lt;BR /&gt;WHERE city_count &amp;gt;= 11;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;PROC TABULATE FORMAT=COMMA10.0 DATA= top10_cities ;&lt;BR /&gt;CLASS perm_city semester;&lt;BR /&gt;TABLE perm_city = 'County' ALL= 'Total',semester = 'Semester' ALL='Total';&lt;BR /&gt;TITLE 'Top Event Attendee Cities' '(Based on Attendee Home Address)';&lt;BR /&gt;FORMAT semester $term_order.;&lt;BR /&gt;run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 15:34:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433136#M281830</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-01T15:34:56Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a PROC tabulate by two variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433162#M281831</link>
      <description>&lt;P&gt;With proc tabulate you can provide different ORDER = option for each class variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;perhaps this will work for your data:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;class perm_city /order=data;&lt;/P&gt;
&lt;P&gt;class semester /order=unformatted;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 16:20:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433162#M281831</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2018-02-01T16:20:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a PROC tabulate by two variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433176#M281832</link>
      <description>&lt;P&gt;No, it's still sorting my semester variable alphabetically.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 01 Feb 2018 17:03:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/433176#M281832</guid>
      <dc:creator>spcoman</dc:creator>
      <dc:date>2018-02-01T17:03:28Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting a PROC tabulate by two variables?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/434031#M281833</link>
      <description>&lt;P&gt;The order option works.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
  value $term_order
  '1' = 'Spring 2018'
  '2' = 'Fall 2017'
  '3' = 'Summer 2017'
  '4' = 'Spring 2017'
  '5' = 'Fall 2016';
run;

data TOP10_CITIES; 
  do PERM_CITY=1 to 5; SEMESTER=cat(PERM_CITY); output; end;
run;

proc tabulate data=TOP10_CITIES ;
  class PERM_CITY ;
  class SEMESTER / order=unformatted descending;
  table PERM_CITY,SEMESTER=''*n='';
  format SEMESTER $term_order.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;DIV class="branch"&gt;
&lt;DIV align="center"&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;\
&lt;TABLE class="table" summary="Procedure Tabulate: Table 1" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;&lt;COLGROUP&gt; &lt;COL /&gt;&lt;/COLGROUP&gt; &lt;COLGROUP&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt; &lt;COL /&gt;&lt;/COLGROUP&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="c m header" scope="col"&gt;&amp;nbsp;&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Fall 2016&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Spring 2017&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Summer 2017&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Fall 2017&lt;/TH&gt;
&lt;TH class="c header" scope="col"&gt;Spring 2018&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;PERM_CITY&lt;/TH&gt;
&lt;TD rowspan="2" class="r b data"&gt;.&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;.&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;.&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;.&lt;/TD&gt;
&lt;TD rowspan="2" class="r b data"&gt;1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;1&lt;/TH&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;2&lt;/TH&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;1&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;3&lt;/TH&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;1&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;4&lt;/TH&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;1&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TH class="l t rowheader" scope="row"&gt;5&lt;/TH&gt;
&lt;TD class="r b data"&gt;1&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;TD class="r b data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Mon, 05 Feb 2018 01:25:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-a-PROC-tabulate-by-two-variables/m-p/434031#M281833</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2018-02-05T01:25:09Z</dc:date>
    </item>
  </channel>
</rss>

