<?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 NUMERIC AS STRING in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349263#M273545</link>
    <description>&lt;P&gt;Actually, that works too. I thought I tried that unsuccesfully but this time it worked. I might have been looking at the wrong variable at the time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Apr 2017 20:36:51 GMT</pubDate>
    <dc:creator>CP2</dc:creator>
    <dc:date>2017-04-11T20:36:51Z</dc:date>
    <item>
      <title>PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349232#M273539</link>
      <description>&lt;P&gt;I am trying to sort numbers as string but they are not sorting in the same order when comparing to an Excel file. In excel it first orders by the number of digits and then by the value of the number. In Sas it orders by the first value of the number regardless as to how many digits. I tried using all the SORTSEQ options with SAS and cannot replicate Excel order. &amp;nbsp;Does anyone know if there is an easy way to order by number value within digit size of the number but maintain the string?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In Excel:&lt;/P&gt;&lt;P&gt;482731&lt;BR /&gt;482731&lt;BR /&gt;482731&lt;BR /&gt;482856&lt;BR /&gt;482856&lt;BR /&gt;482856&lt;BR /&gt;2502546&lt;BR /&gt;2502546&lt;/P&gt;&lt;P&gt;2539454&lt;BR /&gt;2539454&lt;BR /&gt;2539454&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In SAS:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2502546&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2502546&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2539454&lt;BR /&gt;2539454&lt;BR /&gt;2539454&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;482731&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;482731&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;482731&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;482856&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;482856&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;482856&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 19:43:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349232#M273539</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2017-04-11T19:43:10Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349241#M273540</link>
      <description>i believe what is happening is the data is being absolute positionally sorted and left aligned. so in sas it is sorting by 2 smaller than 4 even though the numbers are longer on the right. what i usually do is add another field with leading zeroes and then sort by that. so then 0 is less than 2...</description>
      <pubDate>Tue, 11 Apr 2017 19:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349241#M273540</guid>
      <dc:creator>me55</dc:creator>
      <dc:date>2017-04-11T19:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349243#M273541</link>
      <description>&lt;P&gt;You could use SQL to sort on the numeric conversion of the text value without having to create a new variable:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
    CREATE TABLE sorted AS
    SELECT *
    FROM txtNums
    ORDER BY input(num, best.);
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Apr 2017 19:58:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349243#M273541</guid>
      <dc:creator>collinelliot</dc:creator>
      <dc:date>2017-04-11T19:58:05Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349250#M273542</link>
      <description>&lt;P&gt;Thanks but&amp;nbsp;I'm looking for the Excel sort order&amp;nbsp;which sorts&amp;nbsp;numeric value ascending based on number of digits. A 6-digit number starting with a higher value is before an 7 digit number starting with a lower number.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:06:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349250#M273542</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2017-04-11T20:06:34Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349258#M273543</link>
      <description>&lt;P&gt;thank you.&amp;nbsp;This worked!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;format NewID z12. &amp;nbsp;;&lt;/P&gt;&lt;P&gt;NewID=OldID ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349258#M273543</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2017-04-11T20:23:57Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349259#M273544</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have a look at the SORTSEQ=linguistic... option. It will do what you need. See example below.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also have a look at this paper: &lt;A href="https://support.sas.com/resources/papers/linguistic_collation.pdf" target="_blank"&gt;https://support.sas.com/resources/papers/linguistic_collation.pdf&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input someString : $32.;
  cards;
482731
482731
482731
2502546
2502546
2539454
2539454
2539454
482856
482856
482856
;

proc sort data=have out=want sortseq=linguistic(numeric_collation=on);
  by someString;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bruno&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:34:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349259#M273544</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-04-11T20:34:17Z</dc:date>
    </item>
    <item>
      <title>Re: PROC SORT NUMERIC AS STRING</title>
      <link>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349263#M273545</link>
      <description>&lt;P&gt;Actually, that works too. I thought I tried that unsuccesfully but this time it worked. I might have been looking at the wrong variable at the time.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2017 20:36:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/PROC-SORT-NUMERIC-AS-STRING/m-p/349263#M273545</guid>
      <dc:creator>CP2</dc:creator>
      <dc:date>2017-04-11T20:36:51Z</dc:date>
    </item>
  </channel>
</rss>

