<?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: Sort by 2nd character of variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593721#M170447</link>
    <description>&lt;P&gt;I need it sorted so that I can add a cumulated percent column later on, and if I start this cum-percent with the 500+ range my export will be wrong&lt;/P&gt;</description>
    <pubDate>Thu, 03 Oct 2019 13:59:45 GMT</pubDate>
    <dc:creator>polpel</dc:creator>
    <dc:date>2019-10-03T13:59:45Z</dc:date>
    <item>
      <title>Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593718#M170445</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I have a series of ranges, and I'd like to sort them in ascending order, except the ascii table is made so that when I use PROC SORT it's all in order except for one observation.&lt;/P&gt;&lt;P&gt;Is there are way to sort the table by the 2nd character of the observations.&lt;/P&gt;&lt;P&gt;Here's the series of ranges that are put as character variable after I've sorted the table. The error is quite explicit:&lt;/P&gt;&lt;P&gt;&amp;gt;500%&lt;BR /&gt;[0%;100%]&lt;BR /&gt;]100%;150%]&lt;BR /&gt;]150%;200%]&lt;BR /&gt;]200%;250%]&lt;BR /&gt;]250%;300%]&lt;BR /&gt;]300%;350%]&lt;BR /&gt;]350%;400%]&lt;BR /&gt;]450%;500%]&lt;/P&gt;&lt;P&gt;As you can see, the +500% range is at the top of the table when it should be at the bottom...&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 13:53:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593718#M170445</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-10-03T13:53:54Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593720#M170446</link>
      <description>&lt;P&gt;This seems to be part of a larger problem. Why do you want to do this sort?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 13:58:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593720#M170446</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-03T13:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593721#M170447</link>
      <description>&lt;P&gt;I need it sorted so that I can add a cumulated percent column later on, and if I start this cum-percent with the 500+ range my export will be wrong&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 13:59:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593721#M170447</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-10-03T13:59:45Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593724#M170448</link>
      <description>I any other language like C, this would be easy, I would just send the strings by the address of the 2nd character (&amp;amp;string[1])</description>
      <pubDate>Thu, 03 Oct 2019 14:02:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593724#M170448</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-10-03T14:02:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593727#M170450</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291423"&gt;@polpel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Basically I have a series of ranges, and I'd like to sort them in ascending order, except the ascii table is made so that when I use PROC SORT it's all in order except for one observation.&lt;/P&gt;
&lt;P&gt;Is there are way to sort the table by the 2nd character of the observations.&lt;/P&gt;
&lt;P&gt;Here's the series of ranges that are put as character variable after I've sorted the table. The error is quite explicit:&lt;/P&gt;
&lt;P&gt;&amp;gt;500%&lt;BR /&gt;[0%;100%]&lt;BR /&gt;]100%;150%]&lt;BR /&gt;]150%;200%]&lt;BR /&gt;]200%;250%]&lt;BR /&gt;]250%;300%]&lt;BR /&gt;]300%;350%]&lt;BR /&gt;]350%;400%]&lt;BR /&gt;]450%;500%]&lt;/P&gt;
&lt;P&gt;As you can see, the +500% range is at the top of the table when it should be at the bottom...&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Agreeing with&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31304"&gt;@PeterClemmensen&lt;/a&gt;, the data should not be stored this way, and this is indicative of some other problem (unless what we are seeing is formatted data). Storing data this way just makes your life difficult, as you see. Better to store ranges by a single numeric value, and format them to appear the way you want.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming this is unformatted data, you could use the SCAN function to extract the first number (ignoring the brackets, percent signs, greater than signs, &lt;EM&gt;etc&lt;/EM&gt;.) and once you have done that, the sort ought to be simple.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:07:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593727#M170450</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-03T14:07:25Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593728#M170451</link>
      <description>I'm just formatting the data for when I export to excel.&lt;BR /&gt;In Excel I search the actual strings, so I need my data stored this way</description>
      <pubDate>Thu, 03 Oct 2019 14:09:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593728#M170451</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-10-03T14:09:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593729#M170452</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291423"&gt;@polpel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I'm just formatting the data for when I export to excel.&lt;BR /&gt;In Excel I search the actual strings, so I need my data stored this way&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I disagree. It is much easier to store data as actual numbers, and then do things in SAS with the actual numbers, and then use SAS PROC FORMAT to make them to appear the way you want. You can send the data to Excel in whatever appearance you want.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:11:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593729#M170452</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-10-03T14:11:37Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593731#M170453</link>
      <description>&lt;P&gt;&amp;nbsp;Does this give the result you expect?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data range;
   input range $ 1-16;
   cards4;
&amp;gt;500%
[0%;100%]
]100%;150%]
]150%;200%]
]200%;250%]
]250%;300%]
]300%;350%]
]350%;400%]
]450%;500%]
;;;;
   run;
proc print;
   run;
proc sort data=range sortseq=linguistic(NUMERIC_COLLATION=ON);
   by range;
   run;
proc print;
   run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Capture.PNG" style="width: 134px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/32925i701879B013F70458/image-size/large?v=v2&amp;amp;px=999" role="button" title="Capture.PNG" alt="Capture.PNG" /&gt;&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:11:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593731#M170453</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-10-03T14:11:36Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593736#M170457</link>
      <description>It is easy see my answer.</description>
      <pubDate>Thu, 03 Oct 2019 14:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593736#M170457</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-10-03T14:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593737#M170458</link>
      <description>&lt;P&gt;Guru&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp; &amp;nbsp;Marvelous. Great! Could you offer a couple of notes to how that works when you have a moment plz. I can add that to my notes. Thank you in advance!&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:23:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593737#M170458</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-10-03T14:23:58Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593740#M170460</link>
      <description>&lt;P&gt;All I know is this from the documentation.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4 class="xis-argument"&gt;NUMERIC_COLLATION=&lt;/H4&gt;
&lt;DIV class="xis-argumentDescription"&gt;
&lt;P class="xis-paraSimpleFirst"&gt;orders integer values within the text by the numeric value instead of characters used to represent the numbers.&lt;/P&gt;
&lt;P class="xis-paraSimpleFirst"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xis-paraSimpleFirst"&gt;&amp;nbsp;&lt;/P&gt;
&lt;/DIV&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:29:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593740#M170460</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2019-10-03T14:29:08Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593743#M170463</link>
      <description>it's perfect! thanks!!!</description>
      <pubDate>Thu, 03 Oct 2019 14:34:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593743#M170463</guid>
      <dc:creator>polpel</dc:creator>
      <dc:date>2019-10-03T14:34:24Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593757#M170469</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/291423"&gt;@polpel&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;I any other language like C, this would be easy, I would just send the strings by the address of the 2nd character (&amp;amp;string[1])&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;It's easy in SAS, too, even if none of the specialist options of PROC SORT (thanks,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;, for the reminder!) was applicable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $;
cards;
Wcar
Xdog
Yapple
Zball
;

proc sql;
select * from have
order by substr(string,2);
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;string
--------
Y&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;a&lt;/FONT&gt;&lt;/STRONG&gt;pple
Z&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;b&lt;/FONT&gt;&lt;/STRONG&gt;all
W&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;c&lt;/FONT&gt;&lt;/STRONG&gt;ar
X&lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;d&lt;/FONT&gt;&lt;/STRONG&gt;og&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2019 14:57:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/593757#M170469</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2019-10-03T14:57:09Z</dc:date>
    </item>
    <item>
      <title>Re: Sort by 2nd character of variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/594259#M170691</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;:&lt;/P&gt;
&lt;P&gt;A very nice and pretty complete compendium of proc SORT's features of this sort has been put together by Derek Morgan:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2773-2018.pdf" target="_self"&gt;https://www.sas.com/content/dam/SAS/support/en/sas-global-forum-proceedings/2018/2773-2018.pdf&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Much better and more systematical than wading through the docs. And it was masterfully presented, too (I did attend the talk).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 05 Oct 2019 16:38:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Sort-by-2nd-character-of-variable/m-p/594259#M170691</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-10-05T16:38:35Z</dc:date>
    </item>
  </channel>
</rss>

