<?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 How to fix variable level position in proc tabulate in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506720#M135824</link>
    <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I want to tabulate a table with counts of races. Each level under variable Race has different frequencies such as:&lt;/P&gt;&lt;P&gt;Race&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;&amp;nbsp;White&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000&lt;/P&gt;&lt;P&gt;&amp;nbsp;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 900&lt;/P&gt;&lt;P&gt;&amp;nbsp;Asian&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 400&lt;/P&gt;&lt;P&gt;&amp;nbsp;Hispanic&amp;nbsp; &amp;nbsp; &amp;nbsp;700&lt;/P&gt;&lt;P&gt;&amp;nbsp;Blank&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/P&gt;&lt;P&gt;&amp;nbsp;Other&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 450&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I set order = data for class variable Race, which sorts N from most count to least. However, I want to fix Blank and Other to always be the bottom 2. How should I code for such arrangement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 Oct 2018 03:37:59 GMT</pubDate>
    <dc:creator>lydiawawa</dc:creator>
    <dc:date>2018-10-23T03:37:59Z</dc:date>
    <item>
      <title>How to fix variable level position in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506720#M135824</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Suppose I want to tabulate a table with counts of races. Each level under variable Race has different frequencies such as:&lt;/P&gt;&lt;P&gt;Race&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N&lt;/P&gt;&lt;P&gt;&amp;nbsp;White&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1000&lt;/P&gt;&lt;P&gt;&amp;nbsp;AA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 900&lt;/P&gt;&lt;P&gt;&amp;nbsp;Asian&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 400&lt;/P&gt;&lt;P&gt;&amp;nbsp;Hispanic&amp;nbsp; &amp;nbsp; &amp;nbsp;700&lt;/P&gt;&lt;P&gt;&amp;nbsp;Blank&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 500&lt;/P&gt;&lt;P&gt;&amp;nbsp;Other&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 450&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I set order = data for class variable Race, which sorts N from most count to least. However, I want to fix Blank and Other to always be the bottom 2. How should I code for such arrangement?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 03:37:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506720#M135824</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2018-10-23T03:37:59Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix variable level position in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506745#M135834</link>
      <description>&lt;P&gt;Afaik not possible within proc tabulate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Just an idea:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;save result from proc tabulate in a dataset&lt;/LI&gt;
&lt;LI&gt;use a data-step and proc format to create a format&lt;/LI&gt;
&lt;LI&gt;use proc report on the dataset created by proc tabulate, clone the variable Race assign the format to the clone and use order + noprint&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;Unfortunately i don't have enough time for a closer look at the problem.&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 07:22:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506745#M135834</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2018-10-23T07:22:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix variable level position in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506765#M135850</link>
      <description>&lt;P&gt;You can do it like this, then ORDER=DATA should work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
  set 
    have(where=(race not in('Other','Blank'))
    have(where=(race='Blank'))
    have(where=(race='Other'))
    ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 10:25:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506765#M135850</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2018-10-23T10:25:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix variable level position in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506773#M135856</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;&amp;nbsp;wrote:
&lt;P&gt;I set order = data for class variable Race, which sorts N from most count to least.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30435"&gt;@lydiawawa&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I don't think your statement is true: order = &lt;EM&gt;freq&lt;/EM&gt; would sort by descending count, whereas order = data sorts values according to their order in the input data set -- unless the additional option PRELOADFMT is specified, and this is the key to your problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You need&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;a format for variable RACE which was defined using the NOTSORTED option of the VALUE statement (of PROC FORMAT)&lt;/LI&gt;
&lt;LI&gt;the options PRELOADFMT and ORDER=DATA of the CLASS statement in PROC TABULATE.&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;The CLASS levels will then be displayed in the order that was used in the format definition (VALUE statement).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* Create a format with the NOTSORTED option */

proc format;
value race (notsorted)
4='White'
1='AA'
2='Asian'
3='Hispanic'
.='Blank'
other='Other';
run;

/* Create test data for demonstration */

data test(drop=n);
input race n;
do _n_=1 to n;
  output;
end;
format race race.;
label race='Race';
cards;
1 900
2 400
3 700
4 1000
5 200
6 250
. 500
run;

/* Use options PRELOADFMT and ORDER=DATA to obtain the desired sort order */

proc tabulate data=test;
class race / missing preloadfmt order=data;
table race, n*f=6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The same works with a character format or a format that is only temporarily applied in the PROC TABULATE step using&amp;nbsp;a FORMAT statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 Oct 2018 10:51:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506773#M135856</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2018-10-23T10:51:14Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix variable level position in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506818#M135881</link>
      <description>&lt;P&gt;Did you try CLASSDATA= ?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data race;
input race;
cards;
6
5
4
1
2
3
.
;
run;

data test(drop=n);
input race n;
do _n_=1 to n;
  output;
end;
label race='Race';
cards;
1 900
2 400
3 700
4 1000
5 200
6 250
. 500
run;


proc tabulate data=test classdata=race;
class race / missing order=data ;
table race, n*f=6.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 Oct 2018 13:24:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/506818#M135881</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-10-23T13:24:47Z</dc:date>
    </item>
    <item>
      <title>Re: How to fix variable level position in proc tabulate</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/507053#M136011</link>
      <description>Hi, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/76464"&gt;@s_lassen&lt;/a&gt;, this will create sub-levels among the original levels? I will then need to feed temp into proc tabulate to produce the desired order?</description>
      <pubDate>Wed, 24 Oct 2018 02:48:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-fix-variable-level-position-in-proc-tabulate/m-p/507053#M136011</guid>
      <dc:creator>lydiawawa</dc:creator>
      <dc:date>2018-10-24T02:48:01Z</dc:date>
    </item>
  </channel>
</rss>

