<?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: How to put words in alphabetical order that are separated by comma in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887606#M350665</link>
    <description>&lt;P&gt;Split the words out into separate variables.&lt;/P&gt;
&lt;P&gt;Sort those variables&lt;/P&gt;
&lt;P&gt;Recombine the variables in order into the current variable&lt;/P&gt;
&lt;P&gt;remove the other variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should provide data in the form of working data step code if you want tested code. at least provide data set names and variable names. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;Untested as no data set provided:&lt;/P&gt;
&lt;PRE&gt;data want;
    set have;
   /* the 5 below should be replaced the maximum number of 
     "words" in the list, 10 should be replaced with the maximum
     length of any of the words
   */
    array t ( 5) $ 10;
   /* countw here gets the number of elements separated by comma*/
    do i=1 to countw(yourvariablename,',');
       /* get the ith "word" separated by commas and assign to an
          element of the array*/
       t[i] = scan(yourvariablename,i,',');
   end;
   /* sort the values this actually places and blanks at the front*/
   call sortc(of t(*));
   /* catx combines values after removing trailing spaces placing the 
      first  parameter, comma in this case between results*/
   yourvariablename = catx(',', of t(*));
  /* drop the unwanted variables the 5 here should match the number of elements defined for the array*/
   drop i  t1-t5;
run;
&lt;/PRE&gt;
&lt;P&gt;of t(*) is the way to refer to all elements of an array for those functions that will accept multiple variables.&lt;/P&gt;</description>
    <pubDate>Thu, 03 Aug 2023 02:38:54 GMT</pubDate>
    <dc:creator>ballardw</dc:creator>
    <dc:date>2023-08-03T02:38:54Z</dc:date>
    <item>
      <title>How to put words in alphabetical order that are separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887605#M350664</link>
      <description>&lt;P&gt;Hi.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have data in a cell that&amp;nbsp; I would like alphabetized:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have:&lt;/P&gt;
&lt;TABLE width="180px"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="63.7812px"&gt;John&lt;/TD&gt;
&lt;TD width="115.219px"&gt;C Plus,B,A&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="63.7812px"&gt;Sarah&lt;/TD&gt;
&lt;TD width="115.219px"&gt;D,A Plus,C Minus&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Want:&lt;/P&gt;
&lt;TABLE width="179"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="64"&gt;John&lt;/TD&gt;
&lt;TD width="115"&gt;A,B,C Plus&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD&gt;Sarah&lt;/TD&gt;
&lt;TD&gt;A Plus,C Minus,D&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you in advance for your efforts&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 02:07:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887605#M350664</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2023-08-03T02:07:46Z</dc:date>
    </item>
    <item>
      <title>Re: How to put words in alphabetical order that are separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887606#M350665</link>
      <description>&lt;P&gt;Split the words out into separate variables.&lt;/P&gt;
&lt;P&gt;Sort those variables&lt;/P&gt;
&lt;P&gt;Recombine the variables in order into the current variable&lt;/P&gt;
&lt;P&gt;remove the other variables.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You really should provide data in the form of working data step code if you want tested code. at least provide data set names and variable names. Instructions here: &lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt; will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the &amp;lt;/&amp;gt; icon or attached as text to show exactly what you have and that we can test code against.&lt;/P&gt;
&lt;P&gt;Untested as no data set provided:&lt;/P&gt;
&lt;PRE&gt;data want;
    set have;
   /* the 5 below should be replaced the maximum number of 
     "words" in the list, 10 should be replaced with the maximum
     length of any of the words
   */
    array t ( 5) $ 10;
   /* countw here gets the number of elements separated by comma*/
    do i=1 to countw(yourvariablename,',');
       /* get the ith "word" separated by commas and assign to an
          element of the array*/
       t[i] = scan(yourvariablename,i,',');
   end;
   /* sort the values this actually places and blanks at the front*/
   call sortc(of t(*));
   /* catx combines values after removing trailing spaces placing the 
      first  parameter, comma in this case between results*/
   yourvariablename = catx(',', of t(*));
  /* drop the unwanted variables the 5 here should match the number of elements defined for the array*/
   drop i  t1-t5;
run;
&lt;/PRE&gt;
&lt;P&gt;of t(*) is the way to refer to all elements of an array for those functions that will accept multiple variables.&lt;/P&gt;</description>
      <pubDate>Thu, 03 Aug 2023 02:38:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887606#M350665</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2023-08-03T02:38:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to put words in alphabetical order that are separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887626#M350673</link>
      <description>&lt;P&gt;A method where the number of elements must not be determined beforehand:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data long;
set have;
if _n_ = 1 then call symputx("l",vlength(string));
do i = 1 to countw(string,",");
  s = scan(string,i,",");
  output;
end;
keep name s;
run;

proc sort data=long;
by name s;
run;

data want;
set long;
by name;
length string $&amp;amp;l.;
retain string;
if first.name
then string = s;
else string = catx(",",string,s);
if last.name;
keep name string;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 03 Aug 2023 07:56:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887626#M350673</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2023-08-03T07:56:03Z</dc:date>
    </item>
    <item>
      <title>Re: How to put words in alphabetical order that are separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887655#M350685</link>
      <description>thank you so much!</description>
      <pubDate>Thu, 03 Aug 2023 10:51:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887655#M350685</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2023-08-03T10:51:30Z</dc:date>
    </item>
    <item>
      <title>Re: How to put words in alphabetical order that are separated by comma</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887656#M350686</link>
      <description>Thank you!</description>
      <pubDate>Thu, 03 Aug 2023 10:51:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-put-words-in-alphabetical-order-that-are-separated-by/m-p/887656#M350686</guid>
      <dc:creator>arde</dc:creator>
      <dc:date>2023-08-03T10:51:40Z</dc:date>
    </item>
  </channel>
</rss>

