<?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 sorting value within a variable in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869077#M343304</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am using EG running SAS 9.4 version and need to know is they any SAS function to sort a value within variable or any other way to achieve the desired output shown below. Thanks for your help.&lt;/P&gt;
&lt;P&gt;Input raw value - X = D; K; B; S; O&lt;/P&gt;
&lt;P&gt;Desired output value - X = B; D; K; O; S&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 11 Apr 2023 11:07:15 GMT</pubDate>
    <dc:creator>1239</dc:creator>
    <dc:date>2023-04-11T11:07:15Z</dc:date>
    <item>
      <title>sorting value within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869077#M343304</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am using EG running SAS 9.4 version and need to know is they any SAS function to sort a value within variable or any other way to achieve the desired output shown below. Thanks for your help.&lt;/P&gt;
&lt;P&gt;Input raw value - X = D; K; B; S; O&lt;/P&gt;
&lt;P&gt;Desired output value - X = B; D; K; O; S&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 11:07:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869077#M343304</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2023-04-11T11:07:15Z</dc:date>
    </item>
    <item>
      <title>Re: sorting value within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869079#M343306</link>
      <description>&lt;P&gt;Is the value a character string? Like "&lt;SPAN&gt;- X = D; K; B; S; O" ?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 11:23:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869079#M343306</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2023-04-11T11:23:34Z</dc:date>
    </item>
    <item>
      <title>Re: sorting value within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869081#M343307</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
    x='D; K; B; S; O;';
run;
data want;
    set have;
    array z{1:100} $ _temporary_;
    do i=1 to countw(x,' ');
        z(i)=scan(x,i,' ');
    end;
    call sortc(of z(*));
    x=catx(' ',of z(*));
    drop i;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 12:06:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869081#M343307</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2023-04-11T12:06:50Z</dc:date>
    </item>
    <item>
      <title>Re: sorting value within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869085#M343310</link>
      <description>&lt;P&gt;Afaik there is no function that can do this.&lt;/P&gt;
&lt;P&gt;Maybe the way the data is read can be changed:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
   length Key Value1-Value26 $ 1;
   infile datalines4 delimiter="=;" truncover;
   input Key Value1-Value26;
   
   array values Value1-Value26;
   
   call sortc(of values[*]);
   
   want = catx(' = ', Key, catx(';', of values[*]));
   
   /*drop Key Value:;*/
   
   datalines4;
X = D; K; B; S; O
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 11 Apr 2023 11:42:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869085#M343310</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2023-04-11T11:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: sorting value within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869155#M343332</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/19799"&gt;@1239&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the "raw values" in your real data are very similar to your example, i.e., the items to be sorted are &lt;EM&gt;single characters&lt;/EM&gt; without duplicates (or you want to remove duplicates, if any), you could combine a few functions to get the desired result.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example for single letters (all uppercase as in your example or all lowercase) in an ASCII environment:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;x=prxchange('s/(\w)/$1; /',-1,compress(collate(65),x,'k'));&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 11 Apr 2023 16:56:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869155#M343332</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2023-04-11T16:56:19Z</dc:date>
    </item>
    <item>
      <title>Re: sorting value within a variable</title>
      <link>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869358#M343384</link>
      <description>&lt;P&gt;Hi andreas,&lt;/P&gt;
&lt;P&gt;Thanks for this code and it worked.&lt;/P&gt;</description>
      <pubDate>Wed, 12 Apr 2023 07:12:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/sorting-value-within-a-variable/m-p/869358#M343384</guid>
      <dc:creator>1239</dc:creator>
      <dc:date>2023-04-12T07:12:22Z</dc:date>
    </item>
  </channel>
</rss>

