<?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: Order proc freq output in order listed from bands in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Order-proc-freq-output-in-order-listed-from-bands/m-p/710952#M218938</link>
    <description>Don't recode your value at all, use a format instead and it will sort correctly if you apply the format instead.&lt;BR /&gt;&lt;BR /&gt;proc freq data=band;&lt;BR /&gt;   tables number_difference;&lt;BR /&gt;   format number_difference diff_band_fmt.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;See the following example on how to create the format. Note that your PROC FORMAT code has to be before your PROC FREQ code. &lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Wed, 13 Jan 2021 00:23:09 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2021-01-13T00:23:09Z</dc:date>
    <item>
      <title>Order proc freq output in order listed from bands</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-proc-freq-output-in-order-listed-from-bands/m-p/710947#M218937</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I currently have the following code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data bands;

&amp;nbsp; &amp;nbsp;length band $ 20;

&amp;nbsp; &amp;nbsp;set test;

&amp;nbsp; &amp;nbsp;if -30&amp;lt;=Number_difference&amp;lt;-20 then band="-30&amp;lt;=Number difference&amp;lt;-20";

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;if -20&amp;lt;=Number_difference&amp;lt;-10 then band="-20&amp;lt;=Number difference&amp;lt;-10";

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;if -10&amp;lt;=Number_difference&amp;lt;-0 then band="-10&amp;lt;=Number difference&amp;lt;0";

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;if 0&amp;lt;=Number_difference&amp;lt;10 then band="0&amp;lt;=Number difference&amp;lt;10";

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;if 10&amp;lt;=Number_difference&amp;lt;20 then band="10&amp;lt;=Number difference&amp;lt;20";

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;if 20&amp;lt;=Number_difference&amp;lt;30 then band="20&amp;lt;=Number difference&amp;lt;30";

&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;else&amp;nbsp;band="Other";

run;



proc freq data=bands;

&amp;nbsp; &amp;nbsp;tables band;

run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The proc freq gives me the order as follows:&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;band&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;-10&amp;lt;=Number difference&amp;lt;0&lt;/P&gt;
&lt;P&gt;-20&amp;lt;=Number difference&amp;lt;-10&lt;/P&gt;
&lt;P&gt;-30&amp;lt;=Number difference&amp;lt;-20&lt;/P&gt;
&lt;P&gt;0&amp;lt;=Number difference&amp;lt;10&lt;/P&gt;
&lt;P&gt;10&amp;lt;=Number difference&amp;lt;20&lt;/P&gt;
&lt;P&gt;20&amp;lt;=Number difference&amp;lt;30&lt;/P&gt;
&lt;P&gt;Other&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I would like the proc freq table to be in the order as shown below. Can someone suggest how I could change my code so the output is shown like this please?&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;band&lt;/U&gt;&lt;/P&gt;
&lt;P&gt;-30&amp;lt;=Number difference&amp;lt;-20&lt;/P&gt;
&lt;P&gt;-20&amp;lt;=Number difference&amp;lt;-10&lt;/P&gt;
&lt;P&gt;-10&amp;lt;=Number difference&amp;lt;0&lt;/P&gt;
&lt;P&gt;0&amp;lt;=Number difference&amp;lt;10&lt;/P&gt;
&lt;P&gt;10&amp;lt;=Number difference&amp;lt;20&lt;/P&gt;
&lt;P&gt;20&amp;lt;=Number difference&amp;lt;30&lt;/P&gt;
&lt;P&gt;Other&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Jan 2021 00:32:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-proc-freq-output-in-order-listed-from-bands/m-p/710947#M218937</guid>
      <dc:creator>Justin9</dc:creator>
      <dc:date>2021-01-13T00:32:35Z</dc:date>
    </item>
    <item>
      <title>Re: Order proc freq output in order listed from bands</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-proc-freq-output-in-order-listed-from-bands/m-p/710952#M218938</link>
      <description>Don't recode your value at all, use a format instead and it will sort correctly if you apply the format instead.&lt;BR /&gt;&lt;BR /&gt;proc freq data=band;&lt;BR /&gt;   tables number_difference;&lt;BR /&gt;   format number_difference diff_band_fmt.;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;See the following example on how to create the format. Note that your PROC FORMAT code has to be before your PROC FREQ code. &lt;BR /&gt;&lt;A href="https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/proceedings/proceedings/sugi30/001-30.pdf&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 13 Jan 2021 00:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-proc-freq-output-in-order-listed-from-bands/m-p/710952#M218938</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2021-01-13T00:23:09Z</dc:date>
    </item>
  </channel>
</rss>

