<?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: Proc sort didn't properly sort in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609647#M76727</link>
    <description>&lt;P&gt;Try to remove some unprintable characters .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set data;&lt;/P&gt;
&lt;P&gt;z=compress(z,' ','s');&lt;/P&gt;
&lt;P&gt;/*&lt;/P&gt;
&lt;P&gt;z=compress(z, ,'ka');&lt;/P&gt;
&lt;P&gt;*/&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort ..........&lt;/P&gt;</description>
    <pubDate>Thu, 05 Dec 2019 11:41:33 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2019-12-05T11:41:33Z</dc:date>
    <item>
      <title>Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609562#M76719</link>
      <description>&lt;P&gt;For example, the unsorted data set looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;z&lt;/P&gt;&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;&lt;P&gt;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;&lt;P&gt;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;&lt;P&gt;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;&lt;P&gt;11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I did&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=data out=sorted ;
by z x;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and tried this too&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=data out=sorted ;
by z;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;But what I got looks like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;x &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;z&lt;/P&gt;&lt;P&gt;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;&lt;P&gt;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;&lt;P&gt;11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;&lt;P&gt;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Why is the bottom two lines not sorted properly? Help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 23:03:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609562#M76719</guid>
      <dc:creator>dupp99</dc:creator>
      <dc:date>2019-12-04T23:03:50Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609566#M76720</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302002"&gt;@dupp99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;For example, the unsorted data set looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;z&lt;/P&gt;
&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;
&lt;P&gt;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;
&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;
&lt;P&gt;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;
&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;
&lt;P&gt;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;
&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;
&lt;P&gt;11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I did&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=data out=sorted ;
by z x;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and tried this too&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=data out=sorted ;
by z;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But what I got looks like:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;z&lt;/P&gt;
&lt;P&gt;19 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;
&lt;P&gt;23 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;
&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;
&lt;P&gt;11 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;
&lt;P&gt;9 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;
&lt;P&gt;22 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ZA&lt;/P&gt;
&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; AL&lt;/P&gt;
&lt;P&gt;21 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Why is the bottom two lines not sorted properly? Help!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Most likely cause in a character that you can't see.&lt;/P&gt;
&lt;P&gt;Also note that posts in the main message window here will remove lots of white space or blank type information so what you posted is likely not what you actually have in your data set.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try using a data step with:&lt;/P&gt;
&lt;P&gt;Put z=&amp;nbsp;&amp;nbsp; z&amp;nbsp;$hex16. ;&lt;/P&gt;
&lt;P&gt;And see&amp;nbsp; what the values following the Z=AL look like. I suspect that you will see one of them has different starting value than 414C&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You might try posting a data step &lt;STRONG&gt;created from your data set&lt;/STRONG&gt; using 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 {i} icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 23:16:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609566#M76720</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-04T23:16:09Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609567#M76721</link>
      <description>&lt;P&gt;I tried the Put z= z $hex16. ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But that doesn't change anything in the dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and the proc sort still got the same output.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 23:24:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609567#M76721</guid>
      <dc:creator>dupp99</dc:creator>
      <dc:date>2019-12-04T23:24:51Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609572#M76722</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/302002"&gt;@dupp99&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I tried the Put z= z $hex16. ;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But that doesn't change anything in the dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;and the proc sort still got the same output.&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I did not imply that it would "fix" anything. I said you could use it to examine the values. Did you see different results for the ones that didn't sort properly? You need to remove something from the data value but depending on what it might be the code needed may differ.&lt;/P&gt;
&lt;P&gt;You might have an encoding issue where some of your data is encoded using a different language scheme, you may just have not printable character (or 3). Show the results of the PUT statement. Paste the result from the LOG into a code box opened using the forum's {I} icon.&lt;/P&gt;</description>
      <pubDate>Wed, 04 Dec 2019 23:57:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609572#M76722</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-12-04T23:57:30Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609573#M76723</link>
      <description>Another possibility:&lt;BR /&gt;&lt;BR /&gt;Run a PROC CONTENTS on your data and see what you find for the variable Z.  It may be that you are looking at formatted values for Z and the data is actually in order by the true (unformatted) value of Z.</description>
      <pubDate>Thu, 05 Dec 2019 00:03:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609573#M76723</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-12-05T00:03:48Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609603#M76725</link>
      <description>&lt;P&gt;When I create data out of what you posted, and run the sort:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input x z $;
datalines;
21         AL
22         ZA
9           BC
19         AL
21         BC
23         AL
9           ZA
11         BC
;

proc sort data=have out=want;
by z;
run;

proc print data=want noobs;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;I get this:&lt;/P&gt;
&lt;PRE&gt; x    z

21    AL
19    AL
23    AL
 9    BC
21    BC
11    BC
22    ZA
 9    ZA
&lt;/PRE&gt;
&lt;P&gt;So it is obvious that what you posted is not your real data, but only what you are shown. Leading blanks, invisible characters, or formats disguise the raw values in your dataset.&lt;/P&gt;
&lt;P&gt;So you need to follow Maxim 3 and get to know your data. Run a proc contents to see if any formats are involved, convert the strings to hex display (use the double length of the variable when specifiying the $HEX format) as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13884"&gt;@ballardw&lt;/a&gt;&amp;nbsp;if no format is in play.&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 06:48:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609603#M76725</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2019-12-05T06:48:42Z</dc:date>
    </item>
    <item>
      <title>Re: Proc sort didn't properly sort</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609647#M76727</link>
      <description>&lt;P&gt;Try to remove some unprintable characters .&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data data;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;set data;&lt;/P&gt;
&lt;P&gt;z=compress(z,' ','s');&lt;/P&gt;
&lt;P&gt;/*&lt;/P&gt;
&lt;P&gt;z=compress(z, ,'ka');&lt;/P&gt;
&lt;P&gt;*/&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;proc sort ..........&lt;/P&gt;</description>
      <pubDate>Thu, 05 Dec 2019 11:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Proc-sort-didn-t-properly-sort/m-p/609647#M76727</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-12-05T11:41:33Z</dc:date>
    </item>
  </channel>
</rss>

