<?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 sort_order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800456#M314891</link>
    <description>&lt;PRE&gt;data range;
*set pf_lemon;
length score_lbl $9. sort_order 8.;
score_lnl="500&amp;lt;=score&amp;lt;540"; sort_order=1; output;
score_lnl="540&amp;lt;=score&amp;lt;560"; sort_order=2; output;
score_lnl="560&amp;lt;=score&amp;lt;580"; sort_order=3; output;
score_lnl="580&amp;lt;=score&amp;lt;600"; sort_order=5; output;
run;
proc sort data=range; by score_lnl;run;&lt;/PRE&gt;&lt;P&gt;I tried this but is it how it suppose to be used? do I add a set statement in to include data set I am looking at? I find this very strange.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HeatherNewton_0-1646567116060.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69187iECB02115E5BD12E3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HeatherNewton_0-1646567116060.png" alt="HeatherNewton_0-1646567116060.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 06 Mar 2022 11:46:22 GMT</pubDate>
    <dc:creator>HeatherNewton</dc:creator>
    <dc:date>2022-03-06T11:46:22Z</dc:date>
    <item>
      <title>sort_order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800456#M314891</link>
      <description>&lt;PRE&gt;data range;
*set pf_lemon;
length score_lbl $9. sort_order 8.;
score_lnl="500&amp;lt;=score&amp;lt;540"; sort_order=1; output;
score_lnl="540&amp;lt;=score&amp;lt;560"; sort_order=2; output;
score_lnl="560&amp;lt;=score&amp;lt;580"; sort_order=3; output;
score_lnl="580&amp;lt;=score&amp;lt;600"; sort_order=5; output;
run;
proc sort data=range; by score_lnl;run;&lt;/PRE&gt;&lt;P&gt;I tried this but is it how it suppose to be used? do I add a set statement in to include data set I am looking at? I find this very strange.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="HeatherNewton_0-1646567116060.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/69187iECB02115E5BD12E3/image-size/medium?v=v2&amp;amp;px=400" role="button" title="HeatherNewton_0-1646567116060.png" alt="HeatherNewton_0-1646567116060.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 11:46:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800456#M314891</guid>
      <dc:creator>HeatherNewton</dc:creator>
      <dc:date>2022-03-06T11:46:22Z</dc:date>
    </item>
    <item>
      <title>Re: sort_order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800457#M314892</link>
      <description>&lt;P&gt;Please, from now on, be specific about the desired output. Do not show us the wrong output and then not state what the correct/desired output is (which is what you did). In this case, I can guess. In many other cases, having us guess is not a good way to get the answer you need.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want the results sorted by the variable sort_order, then you need to tell PROC SORT to sort by that variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=range; by sort_order; run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 11:59:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800457#M314892</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-06T11:59:44Z</dc:date>
    </item>
    <item>
      <title>Re: sort_order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800482#M314917</link>
      <description>&lt;P&gt;Your program does not produce the results you display.&amp;nbsp; I ran your program:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data range;
  *set pf_lemon;
  length score_lbl $9. sort_order 8.;
  score_lnl="500&amp;lt;=score&amp;lt;540"; sort_order=1; output;
  score_lnl="540&amp;lt;=score&amp;lt;560"; sort_order=2; output;
  score_lnl="560&amp;lt;=score&amp;lt;580"; sort_order=3; output;
  score_lnl="580&amp;lt;=score&amp;lt;600"; sort_order=5; output;
run;
proc sort data=range; by score_lnl;run;
proc print;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The proc print produces this:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;The SAS System                                                     23:12 Friday, March 4, 2022   8

       score_    sort_
Obs     lbl      order      score_lnl

 1                 1      500&amp;lt;=score&amp;lt;540
 2                 2      540&amp;lt;=score&amp;lt;560
 3                 3      560&amp;lt;=score&amp;lt;580
 4                 5      580&amp;lt;=score&amp;lt;600

&lt;/PRE&gt;
&lt;P&gt;which is &lt;EM&gt;&lt;STRONG&gt;not the order you display&lt;/STRONG&gt;&lt;/EM&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now, I don't recommend using a variable like score_1n1 for sorting purposes, because, as a character variable, it will use &lt;EM&gt;&lt;STRONG&gt;lexicographic order&lt;/STRONG&gt;&lt;/EM&gt;.&amp;nbsp; That is, a value like.&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;'&lt;STRONG&gt;80&amp;lt;=score&amp;lt;=95&lt;/STRONG&gt;'&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;WILL FOLLOW&lt;/STRONG&gt; values like&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;SPAN&gt;'&lt;/SPAN&gt;&lt;STRONG style="font-family: inherit;"&gt;500&amp;lt;=score&amp;lt;540&lt;/STRONG&gt;&lt;SPAN&gt;'.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Better to use the &lt;STRONG&gt;sort_order&lt;/STRONG&gt; variable you created.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 16:54:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800482#M314917</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-06T16:54:12Z</dc:date>
    </item>
    <item>
      <title>Re: sort_order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800497#M314926</link>
      <description>&lt;P&gt;Hi Mark,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I generally agree with you recommendation to not to use "score_1n1" like variables for sorting, but just to remind, there is "numeric_collation=on" option available.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
  score_lnl='500&amp;lt;=score&amp;lt;540'; output;
  score_lnl='80&amp;lt;=score&amp;lt;=95'; output;
  score_lnl='1500&amp;lt;=score&amp;lt;1540'; output;
run;

proc SORT
  data=test
  out =test2
  SORTSEQ=LINGUISTIC(NUMERIC_COLLATION=ON);

  by score_lnl;
run;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 20:01:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800497#M314926</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2022-03-06T20:01:39Z</dc:date>
    </item>
    <item>
      <title>Re: sort_order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800499#M314928</link>
      <description>&lt;P&gt;Great tip, &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;. I keep forgetting about that option myself.&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 20:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800499#M314928</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-03-06T20:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: sort_order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800502#M314930</link>
      <description>&lt;P&gt;... As do I (obviously).&amp;nbsp; Thanks&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/35763"&gt;@yabwon&lt;/a&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 06 Mar 2022 21:08:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sort-order/m-p/800502#M314930</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-03-06T21:08:04Z</dc:date>
    </item>
  </channel>
</rss>

