<?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: Rearranging a Character Strings Into alphabetical order in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394728#M277958</link>
    <description>Have a look at the CALL SORTC routine.&lt;BR /&gt;Define an array, put your chars into the array elements and then use the CALL SORTC.&lt;BR /&gt;&lt;BR /&gt;What is the use case for this data manipulation?</description>
    <pubDate>Mon, 11 Sep 2017 16:28:36 GMT</pubDate>
    <dc:creator>BrunoMueller</dc:creator>
    <dc:date>2017-09-11T16:28:36Z</dc:date>
    <item>
      <title>Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394722#M277955</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was given a dataset with first name and last name variables and asked to concatonate these and then order the&amp;nbsp;full name&amp;nbsp;alphabetically. I have managed to concatonate the names but I am struggling to order the full name. Hopefully the example below will clear things up.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I had:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;fname&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; sname&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Jim&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Smith&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Tom&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Bell&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data currently:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;fullname&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;JimSmith&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;TomBell&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data I need:&lt;/P&gt;&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;fullname2&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;hiiJmmSt&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;BellmoT&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Apologies if this has been answered but I have not found anything on my searches!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 16:06:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394722#M277955</guid>
      <dc:creator>skibur</dc:creator>
      <dc:date>2017-09-11T16:06:41Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394726#M277956</link>
      <description>This looks like homework.  My guess would be you would set up a loop to break each concatenated name into individual characters, dump them in an array one by one, sort the array, and output the contents.</description>
      <pubDate>Mon, 11 Sep 2017 16:25:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394726#M277956</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-11T16:25:15Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394727#M277957</link>
      <description>&lt;P&gt;&lt;STRONG&gt;Data&lt;/STRONG&gt; currently;&lt;/P&gt;&lt;P&gt;input fullname $20.;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;JimSmith&lt;/P&gt;&lt;P&gt;TomBell&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;set currently;&lt;/P&gt;&lt;P&gt;array t(&lt;STRONG&gt;50&lt;/STRONG&gt;) $&amp;nbsp; _temporary_;&lt;/P&gt;&lt;P&gt;call missing(of t(*));&lt;/P&gt;&lt;P&gt;do _n_=&lt;STRONG&gt;1&lt;/STRONG&gt; to length(strip(fullname));&lt;/P&gt;&lt;P&gt;t(_n_)=lowcase(char(fullname,_n_));&lt;/P&gt;&lt;P&gt;end;call sortc(of t(*));newname=cats(of t(*));&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 16:27:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394727#M277957</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-11T16:27:55Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394728#M277958</link>
      <description>Have a look at the CALL SORTC routine.&lt;BR /&gt;Define an array, put your chars into the array elements and then use the CALL SORTC.&lt;BR /&gt;&lt;BR /&gt;What is the use case for this data manipulation?</description>
      <pubDate>Mon, 11 Sep 2017 16:28:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394728#M277958</guid>
      <dc:creator>BrunoMueller</dc:creator>
      <dc:date>2017-09-11T16:28:36Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394729#M277959</link>
      <description>I can see why it looks like homework! But no its for a work project and I am a relative beginner and it was causing me issues. I wouldnt have came to here without having a go myself.&lt;BR /&gt;&lt;BR /&gt;Thanks for the advice, it is much appreciated!</description>
      <pubDate>Mon, 11 Sep 2017 16:28:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394729#M277959</guid>
      <dc:creator>skibur</dc:creator>
      <dc:date>2017-09-11T16:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394730#M277960</link>
      <description>Thank you so much. I will try to understand this.</description>
      <pubDate>Mon, 11 Sep 2017 16:31:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394730#M277960</guid>
      <dc:creator>skibur</dc:creator>
      <dc:date>2017-09-11T16:31:06Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394731#M277961</link>
      <description>Thanks for your advice. I dont want to say too much but its for data matching with another work data set.</description>
      <pubDate>Mon, 11 Sep 2017 16:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394731#M277961</guid>
      <dc:creator>skibur</dc:creator>
      <dc:date>2017-09-11T16:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394750#M277962</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;data matching with another work data set.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hmm.&amp;nbsp; "Tim Mott" and "Tom Mitt" will not match in name form, but will match in sorted anagram form. That could be interesting.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 17:06:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394750#M277962</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-11T17:06:35Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394751#M277963</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/164201"&gt;@skibur&lt;/a&gt;&amp;nbsp; I think your question has been answered. Please close the thread. It's way too simple question&lt;/P&gt;</description>
      <pubDate>Mon, 11 Sep 2017 17:08:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394751#M277963</guid>
      <dc:creator>Andygray</dc:creator>
      <dc:date>2017-09-11T17:08:53Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394766#M277964</link>
      <description>Not that simple for me.</description>
      <pubDate>Mon, 11 Sep 2017 17:23:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/394766#M277964</guid>
      <dc:creator>HB</dc:creator>
      <dc:date>2017-09-11T17:23:02Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/936388#M368069</link>
      <description>&lt;P&gt;Using compress with the whole alphabet at the first argument, your text as second argument, and 'k' modifier to keep letters for the alphabet as they appear.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=""&gt;data test;
input fname $ sname $ ;
datalines;
John Smith
Tom Bell
;

data test;
	set test;
	fullname = cats(fname, sname);
	fullname2 = compress('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', fullname, 'k');
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Jul 2024 15:30:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/936388#M368069</guid>
      <dc:creator>bodowd</dc:creator>
      <dc:date>2024-07-19T15:30:33Z</dc:date>
    </item>
    <item>
      <title>Re: Rearranging a Character Strings Into alphabetical order</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/936414#M368077</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116714"&gt;@bodowd&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Using compress with the whole alphabet at the first argument, your text as second argument, and 'k' modifier to keep letters for the alphabet as they appear.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=""&gt;data test;
input fname $ sname $ ;
datalines;
John Smith
Tom Bell
;

data test;
	set test;
	fullname = cats(fname, sname);
	fullname2 = compress('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', fullname, 'k');
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/116714"&gt;@bodowd&lt;/a&gt;&amp;nbsp;:&amp;nbsp;&amp;nbsp;Very nice, because you can trivially change the desired order of characters in the result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test;
	set test;
	fullname = cats(fname, sname);
	fullname2 = compress('AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz', fullname, 'k');
	fullname3 = compress('ZzYyXxWwVvUuTtSsRrQqPpOoNnMmLlKkJjIiHhGgFfEeDdCcBbAa', fullname, 'k');
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But be careful - In the absence of a LENGTH declaration, the resulting FULLNAME2 and 3 lengths are determined by the first argument of the compress function - i.e. length 52 in this case.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Also, letters that appear more than once in the original, appear only once in the result.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jul 2024 19:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Rearranging-a-Character-Strings-Into-alphabetical-order/m-p/936414#M368077</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2024-07-19T19:15:28Z</dc:date>
    </item>
  </channel>
</rss>

