<?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 a list of comma separated values in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526796#M143547</link>
    <description>No, varying lengths are possible. Good point.&lt;BR /&gt;</description>
    <pubDate>Sun, 13 Jan 2019 22:33:02 GMT</pubDate>
    <dc:creator>buechler66</dc:creator>
    <dc:date>2019-01-13T22:33:02Z</dc:date>
    <item>
      <title>Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526779#M143531</link>
      <description>&lt;P&gt;Would it be possible to reorder a list of comma separated values stored as a variable string?&amp;nbsp; The string could have any number of comma separated values or it could have just one value with no comma in some cases.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example a character variable stored with the value of:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'12345, 54321, 23456, 65432'&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Could it be reordered numerically (or alphabetically if it includes alphabetic characters) to appear as:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;'12345, 23456, 54321, 65432'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions would very helpful.&amp;nbsp; Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 21:06:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526779#M143531</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-01-13T21:06:07Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526781#M143533</link>
      <description>&lt;P&gt;Something like this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   length string $100;
   string='12345, 54321, 23456, 65432';

   array num{4} $;

   do i=1 to dim(num);
      num[i]=scan(string, i);
   end;

   call sortc(of num[*]);

   newstring=catx(', ', of num[*]);

   put string= // newstring=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jan 2019 21:17:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526781#M143533</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-13T21:17:51Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526782#M143534</link>
      <description>This is awesome. I didn't know such a call routine existed. This is a huge help. Thanks so much for your time!</description>
      <pubDate>Sun, 13 Jan 2019 21:20:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526782#M143534</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-01-13T21:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526783#M143535</link>
      <description>&lt;P&gt;No problem, glad to help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 21:20:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526783#M143535</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-13T21:20:35Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526790#M143541</link>
      <description>&lt;P&gt;An alternative approach, where you do not have to specify the number of entries (4) beforehand&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   declare hash h(ordered:"Y");
   h.definekey('num');
   h.definedone();
   declare hiter hi('h');

   length string $100 newstring $100;
   string='12345, 54321, 23456, 65432';

   do i=1 to countw(string, ',');
      num=scan(string, i, ', ');
      h.add();
   end;

   do while (hi.next()=0);
      newstring=catx(', ', newstring, num);
   end;

  put string // newstring;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jan 2019 22:13:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526790#M143541</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-13T22:13:42Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526792#M143543</link>
      <description>&lt;P&gt;Are the strings always 5 bytes of chars in length as your example ?&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 22:24:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526792#M143543</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-13T22:24:52Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526796#M143547</link>
      <description>No, varying lengths are possible. Good point.&lt;BR /&gt;</description>
      <pubDate>Sun, 13 Jan 2019 22:33:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526796#M143547</guid>
      <dc:creator>buechler66</dc:creator>
      <dc:date>2019-01-13T22:33:02Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526797#M143548</link>
      <description>&lt;P&gt;In the numeric case, you can alter the hash object code as&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
   declare hash h(ordered:"Y");
   h.definekey('num');
   h.definedone();
   declare hiter hi('h');

   length string $100 newstring $100;
   string='12345, 123456, 54321, 23456, 65432';

   do i=1 to countw(string, ',');
      num=input(scan(string, i, ', '), 8.);
      h.add();
   end;

   do while (hi.next()=0);
      newstring=catx(', ', newstring, num);
   end;

  put string // newstring;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 13 Jan 2019 22:36:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526797#M143548</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-01-13T22:36:12Z</dc:date>
    </item>
    <item>
      <title>Re: Order a list of comma separated values</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526799#M143549</link>
      <description>&lt;P&gt;Ok. I think i would stick to arrays and not hash. You can initiallise the subscript as high as you want. Catx anyways strips of the leading and trailing blanks. Also, you don't have to loop through te string to split once and then loop through the hasn contents. Two sets of loops are not needed i think.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also Hash contents has to be cleared for every iteration&lt;/P&gt;
&lt;P&gt;h.clear();&lt;/P&gt;
&lt;P&gt;A lot of overhead after all.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Plus temporary arrays are much faster although a call missing would be needed. So for this scenario, i personally would go for temp arrays&lt;/P&gt;</description>
      <pubDate>Sun, 13 Jan 2019 22:40:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Order-a-list-of-comma-separated-values/m-p/526799#M143549</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-13T22:40:08Z</dc:date>
    </item>
  </channel>
</rss>

