<?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 character variable in alphabetical order from A-Z in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818441#M323057</link>
    <description>&lt;P&gt;PROC SORT will sort by the ASCII codes of the strings. So all lowercase letters come after all uppercase letters.&lt;/P&gt;
&lt;P&gt;So a value like 'w10001' will come before 'z' but it will be after 'Z'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to sort without regard to case then make a new variable using UPCASE() function and sort on that variable instead.&lt;/P&gt;</description>
    <pubDate>Wed, 15 Jun 2022 18:52:57 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2022-06-15T18:52:57Z</dc:date>
    <item>
      <title>Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818430#M323051</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Please I need help with SAS code for sorting a character variable in alphabetical order from A-Z.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:33:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818430#M323051</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2022-06-15T18:33:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818431#M323052</link>
      <description>&lt;P&gt;PROC SORT will do this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I'm guessing that there is more to your question, as I am sure you knew this already. So please, instead of saying as little as possible on this subject, give a full complete explanation, with emphasis on &lt;STRONG&gt;FULL&lt;/STRONG&gt; and emphasis on &lt;STRONG&gt;COMPLETE&lt;/STRONG&gt;.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818431#M323052</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-15T18:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818432#M323053</link>
      <description>&lt;P&gt;That is default sort order in proc sort on a character variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=sashelp.class out=class_sorted_by_name;
by name;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319831"&gt;@UcheOkoro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;Please I help with SAS code for sorting a character variable in alphabetical order from A-Z.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:33:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818432#M323053</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-15T18:33:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818435#M323054</link>
      <description>&lt;P&gt;I have a character variable with drug names. However, there are levels with non-drug names eg w10001. I used the proc sort statement but it did not work. The data is not sorted in alphabetical order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=long_finder;
by DRUGID ;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:39:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818435#M323054</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2022-06-15T18:39:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818437#M323055</link>
      <description>&lt;P&gt;Thank you for you response . I tried the proc sort statement but it did not work.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:42:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818437#M323055</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2022-06-15T18:42:52Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818438#M323056</link>
      <description>&lt;P&gt;Look at the output from this and see if the values are "sorted";&lt;/P&gt;
&lt;PRE&gt;Proc print data=long_finder;
   var drugid;
   format drugid;
run;&lt;/PRE&gt;
&lt;P&gt;This will print the values without any custom format, which I am making a guess from some of your other posts that the Drugid may have a custom format applied.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The SORT order would &lt;STRONG&gt;not&lt;/STRONG&gt; use the formatted value of the variable, only the actual value.&lt;/P&gt;
&lt;P&gt;You do not say why you need the order. It might be that for display purposes you could use Proc Report and Define the order for the variable as Formatted using that variable as a Group or Order variable.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:47:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818438#M323056</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-15T18:47:51Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818441#M323057</link>
      <description>&lt;P&gt;PROC SORT will sort by the ASCII codes of the strings. So all lowercase letters come after all uppercase letters.&lt;/P&gt;
&lt;P&gt;So a value like 'w10001' will come before 'z' but it will be after 'Z'.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to sort without regard to case then make a new variable using UPCASE() function and sort on that variable instead.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:52:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818441#M323057</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-06-15T18:52:57Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818443#M323058</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319831"&gt;@UcheOkoro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Thank you for you response . I tried the proc sort statement but it did not work.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Did not work is awful vague.&lt;BR /&gt;&lt;BR /&gt;Are there errors in the log?: Post the code and log in a code box opened with the "&amp;lt;/&amp;gt;" to maintain formatting of error messages.&lt;BR /&gt;&lt;BR /&gt;No output? Post any log in a code box.&lt;BR /&gt;&lt;BR /&gt;Unexpected output?&lt;STRONG&gt; Provide input data in the form of data step code pasted into a code box&lt;/STRONG&gt;, the actual results and the expected results. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the "&amp;lt;/&amp;gt;" icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 18:54:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818443#M323058</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-15T18:54:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818448#M323059</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319831"&gt;@UcheOkoro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a character variable with drug names. However, there are levels with non-drug names eg w10001. I used the proc sort statement but it did not work. The data is not sorted in alphabetical order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=long_finder;
by DRUGID ;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Saying it did not work ... is not a FULL COMPLETE explanation, as we don't have a clue what didn't work. Saying you have non-drug names like w10001 is not a FULL COMPLETE explanation because I don't see how that is even relevant to sorting. Please, show us the data (or a portion of it) and then explain (FULL COMPLETE) what results you would like to see from this sort.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 19:09:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818448#M323059</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-06-15T19:09:46Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818462#M323060</link>
      <description>&lt;P&gt;Yes it did, but it's likely &lt;STRONG&gt;not the order you want&lt;/STRONG&gt;.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Show what you want versus what proc sort did output.&amp;nbsp;&lt;/P&gt;
&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/319831"&gt;@UcheOkoro&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have a character variable with drug names. However, there are levels with non-drug names eg w10001. I used the proc sort statement but it did not work. The data is not sorted in alphabetical order.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=long_finder;
by DRUGID ;run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 19:44:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818462#M323060</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-15T19:44:05Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818473#M323062</link>
      <description>&lt;P&gt;Thank you for your response. The following are my code, the log output and portions of the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=long_finder out=long_finder2;
by drugid;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UcheOkoro_0-1655322502606.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72351iCC0ADAFDE3DD400E/image-size/medium?v=v2&amp;amp;px=400" role="button" title="UcheOkoro_0-1655322502606.png" alt="UcheOkoro_0-1655322502606.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UcheOkoro_1-1655322551307.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72352iEBD2F92419D208E0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="UcheOkoro_1-1655322551307.png" alt="UcheOkoro_1-1655322551307.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UcheOkoro_3-1655322664513.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72354i537F3890EE68CC29/image-size/medium?v=v2&amp;amp;px=400" role="button" title="UcheOkoro_3-1655322664513.png" alt="UcheOkoro_3-1655322664513.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="UcheOkoro_2-1655322576264.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72353i6A8C2EC71547DCE0/image-size/medium?v=v2&amp;amp;px=400" role="button" title="UcheOkoro_2-1655322576264.png" alt="UcheOkoro_2-1655322576264.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
341215  proc sort data=long_finder out=long_finder2;
341216  by drugid;
341217  run;

NOTE: There were 6185010 observations read from the data set WORK.LONG_FINDER.
NOTE: The data set WORK.LONG_FINDER2 has 6185010 observations and 3 variables.
NOTE: PROCEDURE SORT used (Total process time):
      real time           2.49 seconds
      cpu time            3.25 seconds

&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 19:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818473#M323062</guid>
      <dc:creator>UcheOkoro</dc:creator>
      <dc:date>2022-06-15T19:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818475#M323064</link>
      <description>&lt;P&gt;Can you show those same screenshots but formatting the variable as $HEX32 format?&lt;/P&gt;
&lt;P&gt;Do they match the hex codes below for the text?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Obs	drugID	                                drug
1	414D4C4F444950494E45202020202020	AMLODIPINE
2	4359434C4F42454E5A415052494E4520	CYCLOBENZAPRINE
3	49425550524F46454E20202020202020	IBUPROFEN
4	4E41202D204E6F2064727567206D656E	NA - No drug mentioned&lt;/PRE&gt;</description>
      <pubDate>Wed, 15 Jun 2022 20:20:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818475#M323064</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-06-15T20:20:16Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818476#M323065</link>
      <description>&lt;P&gt;Did you try the Proc Print I suggested that suppresses the FORMAT for the variable?&lt;/P&gt;
&lt;P&gt;If that output is too much than try:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;Proc freq data=long_finder;
   tables drugid;
   format drugid;
run;&lt;/PRE&gt;
&lt;P&gt;And show the output from that.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What exactly is the FORMAT assigned to the variable Drugid?&lt;/P&gt;
&lt;P&gt;If it is not something like $40. , i.e. any name other than $ followed by a number, then there is a CUSTOM format assigned. Proc Sort will not use the formatted value to sort the data.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are some options related to national language sort preferences and how values incorporating digits may be sorted for Proc Sort but they all work on the actual value of the variable.&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 20:25:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818476#M323065</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-15T20:25:23Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818480#M323068</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/319831"&gt;@UcheOkoro&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the output strongly suggests that&amp;nbsp;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884" target="_blank" rel="noopener"&gt;ballardw&lt;/A&gt; nailed it: You are looking at formatted values which are sorted by the underlying internal DRUGID values (perhaps codes from a drug dictionary).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then you may want to execute these two steps to obtain the alphabetical sort order by formatted values:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;Find out the relevant format name from PROC CONTENTS output.&lt;BR /&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc contents data=long_finder(keep=drugid);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;LI&gt;Replace "&lt;FONT color="#FF0000"&gt;&lt;EM&gt;$drugfmt.&lt;/EM&gt;&lt;/FONT&gt;" in the code below by the real format name determined in step 1 (omit the leading dollar sign if DRUGID turns out to be a numeric variable) and run the code.&lt;BR /&gt;
&lt;PRE&gt;data _tmp / view=_tmp;
set long_finder;
_seqno=_n_;
run;

proc sql;
create table long_finder2(drop=_seqno) as
select * from _tmp
order by put(drugid, &lt;FONT color="#FF0000"&gt;&lt;EM&gt;$drugfmt.&lt;/EM&gt;&lt;/FONT&gt;), _seqno;
drop view _tmp;
quit;&lt;/PRE&gt;
&lt;/LI&gt;
&lt;/OL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Edit: To overcome the&amp;nbsp;uppercase/lowercase problem mentioned by &lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159" target="_blank" rel="noopener"&gt;Tom&lt;/A&gt; you can add the UPCASE or UPPER function to the ORDER BY clause:&lt;/P&gt;
&lt;PRE&gt;order by &lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;upper(&lt;/STRONG&gt;&lt;/FONT&gt;put(drugid, &lt;FONT color="#FF0000"&gt;&lt;EM&gt;$drugfmt.&lt;/EM&gt;&lt;/FONT&gt;)&lt;FONT color="#3366FF"&gt;&lt;STRONG&gt;)&lt;/STRONG&gt;&lt;/FONT&gt;, _seqno;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 20:59:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818480#M323068</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2022-06-15T20:59:10Z</dc:date>
    </item>
    <item>
      <title>Re: Sorting character variable in alphabetical order from A-Z</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818486#M323070</link>
      <description>&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ballardw_0-1655327114623.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72355i20B15174CDE97E45/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ballardw_0-1655327114623.png" alt="ballardw_0-1655327114623.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;Remember this from your question about "Coverting character variables from wide to long"? If this LONG_FINDER data set is the result of that process it is almost certain that the values are still the codes that use this $MEDCODF. format and the underlying values are the same here:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="ballardw_1-1655327284140.png" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/72357i35E2F55D9C64B539/image-size/medium?v=v2&amp;amp;px=400" role="button" title="ballardw_1-1655327284140.png" alt="ballardw_1-1655327284140.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;With -9 being the sorted value that means "NA - No drug mentioned".&lt;/P&gt;</description>
      <pubDate>Wed, 15 Jun 2022 21:08:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sorting-character-variable-in-alphabetical-order-from-A-Z/m-p/818486#M323070</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-06-15T21:08:50Z</dc:date>
    </item>
  </channel>
</rss>

