<?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 nominal variables in PROC FREQ (Based on order in PROC FORMAT) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250023#M47111</link>
    <description>&lt;P&gt;Don't convert the variable, use the original variable and apply the format. SAS will sort it correctly for you.&lt;/P&gt;
&lt;P&gt;There's two sets of code below, hopefully it illustrates the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value mpg_band
      	LOW - &amp;lt;16 = '&amp;lt;=15'
      	16 - &amp;lt;18 = '16-17'
	  	18 - &amp;lt;25 = '18-24'
		25 - &amp;lt;30 = '25-29'
		30 - &amp;lt;35 = '30-34'
		35 - &amp;lt;40 = '35-39'
		40 - &amp;lt;45 = '40-44'
		45 - &amp;lt;50 = '45-49'
		50 - &amp;lt;55 = '50-54'
		55 - &amp;lt;60 = '55-59'
		60 - &amp;lt;65 = '60-64'
		65 - &amp;lt;70 = '65-69'
		70 - &amp;lt;75 = '70-74'
		75 - HIGH = '75+';
run;
data new_data;
	set SASHELP.cars;
	mpg_band = put(mpg_highway,mpg_band.);
run;

proc sort data=new_data;
by origin mpg_highway;
run;

proc freq data=new_data;
by origin;
	tables origin*mpg_highway /out=freq_data;
        format mpg_highway mpg_band.;
run;

OR

proc freq data=sashelp.cars;
tables origin*mpg_highway/out=freq_data2;
format mpg_highway mpg_band.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Mon, 15 Feb 2016 06:31:40 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-02-15T06:31:40Z</dc:date>
    <item>
      <title>Sorting nominal variables in PROC FREQ (Based on order in PROC FORMAT)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250019#M47110</link>
      <description>&lt;P&gt;Hi - Just wondering how I can use the order in PROC FORMAT to sort output in a table.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sample code:&lt;/P&gt;&lt;PRE&gt;proc format;
   value mpg_band
      	LOW - &amp;lt;16 = '&amp;lt;=15'
      	16 - &amp;lt;18 = '16-17'
	  	18 - &amp;lt;25 = '18-24'
		25 - &amp;lt;30 = '25-29'
		30 - &amp;lt;35 = '30-34'
		35 - &amp;lt;40 = '35-39'
		40 - &amp;lt;45 = '40-44'
		45 - &amp;lt;50 = '45-49'
		50 - &amp;lt;55 = '50-54'
		55 - &amp;lt;60 = '55-59'
		60 - &amp;lt;65 = '60-64'
		65 - &amp;lt;70 = '65-69'
		70 - &amp;lt;75 = '70-74'
		75 - HIGH = '75+';
run;
data new_data;
	set SASHELP.cars;
	mpg_band = put(mpg_highway,mpg_band.);
run;

proc sort data=new_data;
by origin mpg_band;
run;
proc freq data=new_data;
	tables origin*mpg_band /out=freq_data;
	by origin NOTSORTED;
run;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;As shown in an extract of the output, the &amp;lt;= 15 is the last column, however I would like it to be the first column ...&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1888i160381264DA04C4F/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help appreciated. &amp;nbsp;Thanks. &amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 06:13:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250019#M47110</guid>
      <dc:creator>mduarte</dc:creator>
      <dc:date>2016-02-15T06:13:35Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting nominal variables in PROC FREQ (Based on order in PROC FORMAT)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250023#M47111</link>
      <description>&lt;P&gt;Don't convert the variable, use the original variable and apply the format. SAS will sort it correctly for you.&lt;/P&gt;
&lt;P&gt;There's two sets of code below, hopefully it illustrates the issue.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value mpg_band
      	LOW - &amp;lt;16 = '&amp;lt;=15'
      	16 - &amp;lt;18 = '16-17'
	  	18 - &amp;lt;25 = '18-24'
		25 - &amp;lt;30 = '25-29'
		30 - &amp;lt;35 = '30-34'
		35 - &amp;lt;40 = '35-39'
		40 - &amp;lt;45 = '40-44'
		45 - &amp;lt;50 = '45-49'
		50 - &amp;lt;55 = '50-54'
		55 - &amp;lt;60 = '55-59'
		60 - &amp;lt;65 = '60-64'
		65 - &amp;lt;70 = '65-69'
		70 - &amp;lt;75 = '70-74'
		75 - HIGH = '75+';
run;
data new_data;
	set SASHELP.cars;
	mpg_band = put(mpg_highway,mpg_band.);
run;

proc sort data=new_data;
by origin mpg_highway;
run;

proc freq data=new_data;
by origin;
	tables origin*mpg_highway /out=freq_data;
        format mpg_highway mpg_band.;
run;

OR

proc freq data=sashelp.cars;
tables origin*mpg_highway/out=freq_data2;
format mpg_highway mpg_band.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 15 Feb 2016 06:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250023#M47111</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-02-15T06:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting nominal variables in PROC FREQ (Based on order in PROC FORMAT)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250033#M47114</link>
      <description>&lt;P&gt;Since you already transform it into character value by PUT() . Try Add a blank before '&amp;lt;=15' .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc format;&lt;BR /&gt; value mpg_band&lt;BR /&gt; &lt;STRONG&gt;LOW - &amp;lt;16 = ' &amp;nbsp;&amp;lt;=15'&lt;/STRONG&gt;&lt;BR /&gt; 16 - &amp;lt;18 = '16-17'&lt;BR /&gt; 18 - &amp;lt;25 = '18-24'&lt;BR /&gt; 25 - &amp;lt;30 = '25-29'&lt;BR /&gt; 30 - &amp;lt;35 = '30-34'&lt;BR /&gt; 35 - &amp;lt;40 = '35-39'&lt;BR /&gt; 40 - &amp;lt;45 = '40-44'&lt;BR /&gt; 45 - &amp;lt;50 = '45-49'&lt;BR /&gt; 50 - &amp;lt;55 = '50-54'&lt;BR /&gt; 55 - &amp;lt;60 = '55-59'&lt;BR /&gt; 60 - &amp;lt;65 = '60-64'&lt;BR /&gt; 65 - &amp;lt;70 = '65-69'&lt;BR /&gt; 70 - &amp;lt;75 = '70-74'&lt;BR /&gt; 75 - HIGH = '75+';&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 08:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250033#M47114</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-02-15T08:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting nominal variables in PROC FREQ (Based on order in PROC FORMAT)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250076#M47122</link>
      <description>&lt;P&gt;You don't need to a new variable you just need the proper options.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
   value mpg_band
      LOW - &amp;lt;16   = '&amp;lt;=15'
      16 - &amp;lt;18    = '16-17'
      18 - &amp;lt;25    = '18-24'
      25 - &amp;lt;30    = '25-29'
      30 - &amp;lt;35    = '30-34'
      35 - &amp;lt;40    = '35-39'
      40 - &amp;lt;45    = '40-44'
      45 - &amp;lt;50    = '45-49'
      50 - &amp;lt;55    = '50-54'
      55 - &amp;lt;60    = '55-59'
      60 - &amp;lt;65    = '60-64'
      65 - &amp;lt;70    = '65-69'
      70 - &amp;lt;75    = '70-74'
      75 - HIGH   = '75+'
      ;
   run;


proc sort data=sashelp.cars out=new_data;
   by origin;
   run;
proc freq data=new_data order=internal;
	tables origin*mpg_highway /out=freq_data;
	by origin;
   format MPG_Highway mpg_band.;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/1889i77D7D40F6618FEE3/image-size/original?v=mpbl-1&amp;amp;px=-1" border="0" alt="Capture.PNG" title="Capture.PNG" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 15 Feb 2016 12:27:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-nominal-variables-in-PROC-FREQ-Based-on-order-in-PROC/m-p/250076#M47122</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2016-02-15T12:27:27Z</dc:date>
    </item>
  </channel>
</rss>

