<?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: Order char values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765279#M242386</link>
    <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how about that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input Category $30.;
cards;
10K-16K
16K-21K
21K-27K
27K-35.5K
2K-6K
6K-10K
All Other
less 2K
more 35.5K
;
Run;

data want;
  set have;
  cat = compress(Category,"-.","kd");
  if cat = "" then cat = '9999';
run;

proc sort data = want sortseq=LINGUISTIC(numeric_colation=on);
  by cat;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 09:40:36 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2021-09-01T09:40:36Z</dc:date>
    <item>
      <title>Order char values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765219#M242371</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to sort the following char values in order to put them in the following order:&lt;/P&gt;
&lt;P&gt;less 2K&lt;BR /&gt;2K-6K&lt;BR /&gt;6K-10K&lt;BR /&gt;10K-16K&lt;BR /&gt;16K-21K&lt;BR /&gt;21K-27K&lt;BR /&gt;27K-35.5K&lt;BR /&gt;more 35.5K&lt;BR /&gt;All Other&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input Category $30.;
cards;
10K-16K
16K-21K
21K-27K
27K-35.5K
2K-6K
6K-10K
All Other
less 2K
more 35.5K
;
Run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 05:27:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765219#M242371</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2021-09-01T05:27:30Z</dc:date>
    </item>
    <item>
      <title>Re: Order char values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765221#M242372</link>
      <description>&lt;P&gt;how about this code?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data next;
  set have;
  catc=scan(category,1);
  if upcase(catc)='ALL' then catn=99;
  else if upcase(catc)='LESS' then catn=1;
  else if upcase(catc)='MORE' then catn=90;
  else catn=input(scan(category,1,'-','A'),best.);
  drop catc;
run;
proc sort data=next out=want(drop=catn);
  by catn;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 05:53:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765221#M242372</guid>
      <dc:creator>japelin</dc:creator>
      <dc:date>2021-09-01T05:53:46Z</dc:date>
    </item>
    <item>
      <title>Re: Order char values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765266#M242385</link>
      <description>&lt;P&gt;How do you assign the category in the first place?&lt;/P&gt;
&lt;P&gt;If you want such categories ordered in a particular way, use a raw numeric value that determines the order, and assign a format that displays the string for it.&lt;/P&gt;
&lt;P&gt;The format code might look like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc format;
value mycat
  0 = "less 2K"
  1 = "2K-6K"
  2 = "6K-10K"
  3 = "10K-16K"
  4 = "16K-21K"
  5 = "21K-27K"
  6 = "27K-35.5K"
  7 = "more 35.5K"
  99 = "All Other"
;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 01 Sep 2021 08:58:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765266#M242385</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2021-09-01T08:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Order char values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765279#M242386</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;how about that:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;
input Category $30.;
cards;
10K-16K
16K-21K
21K-27K
27K-35.5K
2K-6K
6K-10K
All Other
less 2K
more 35.5K
;
Run;

data want;
  set have;
  cat = compress(Category,"-.","kd");
  if cat = "" then cat = '9999';
run;

proc sort data = want sortseq=LINGUISTIC(numeric_colation=on);
  by cat;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 09:40:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765279#M242386</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-09-01T09:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Order char values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765318#M242407</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;What is the way to sort the following char values in order to put them in the following order:&lt;/P&gt;
&lt;P&gt;less 2K&lt;BR /&gt;2K-6K&lt;BR /&gt;6K-10K&lt;BR /&gt;10K-16K&lt;BR /&gt;16K-21K&lt;BR /&gt;21K-27K&lt;BR /&gt;27K-35.5K&lt;BR /&gt;more 35.5K&lt;BR /&gt;All Other&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;You have been asking this (or very similar) questions for probably 2 years now.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Leave numeric variables as numeric. Then they will sort as numeric. Use custom formats to make them appear 10k-16k, and so on.&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 12:09:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-char-values/m-p/765318#M242407</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2021-09-01T12:09:52Z</dc:date>
    </item>
  </channel>
</rss>

