<?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 How to check whether two strings are anagram or not. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920684#M362611</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
input string_1 : $12. string_2 $12.;
datalines;
elbow below
brog grob
yet tey
abc efg
;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;OUTPUT to print check string_1&amp;nbsp; with string_2 content all letters are match then this will be anagram string :&lt;/P&gt;&lt;P&gt;example:&amp;nbsp; elbow &amp;amp; below both are having same words then this should be print as anagram string ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 18 Mar 2024 13:47:44 GMT</pubDate>
    <dc:creator>ganeshmule</dc:creator>
    <dc:date>2024-03-18T13:47:44Z</dc:date>
    <item>
      <title>How to check whether two strings are anagram or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920684#M362611</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="sas"&gt;data have;
input string_1 : $12. string_2 $12.;
datalines;
elbow below
brog grob
yet tey
abc efg
;
run;&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;OUTPUT to print check string_1&amp;nbsp; with string_2 content all letters are match then this will be anagram string :&lt;/P&gt;&lt;P&gt;example:&amp;nbsp; elbow &amp;amp; below both are having same words then this should be print as anagram string ;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 13:47:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920684#M362611</guid>
      <dc:creator>ganeshmule</dc:creator>
      <dc:date>2024-03-18T13:47:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to check weather provided two strings are anagram  or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920686#M362612</link>
      <description>&lt;P&gt;&lt;STRIKE&gt;If you don't have multi byte characters in your string&lt;/STRIKE&gt; do this:&lt;/P&gt;
&lt;P&gt;[EDIT:]&lt;/P&gt;
&lt;P&gt;unfortunately for multi byte characters it can fails (example in P.S.)...&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string_1 : $12. string_2 $12.;
datalines;
elbow below
brog grob
yet tey
abc efg
xxxxx xxxx
żółć ćółż
空手道 道手空
;
run;
proc print;
run;

filename f TEMP;
data _null_; file f; put; run;

%let n=10; /* max number of letters */

data want;
  set have;
  infile f truncover;

  input @1 @;
  _infile_ = string_1;
  input @1 (str1_1-str1_&amp;amp;n.) ($1.) @@;
  _infile_ = string_2;
  input @1 (str2_1-str2_&amp;amp;n.) ($1.) @@;

  call sortc(of str1_:);
  call sortc(of str2_:);

  anagram = (cats(of str1_:) = cats(of str2_:));

  drop str1_: str2_:;
run;
filename f CLEAR;

proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;{EDIT:}&lt;/P&gt;
&lt;P&gt;P.S.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
x="空";
y=char(x,1)!!char(x,3)!!char(x,2);
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;X and Y are two different characters but their bytes are "the same after sorting"...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;P.S.2 I'll find you a different solution.&lt;/P&gt;
&lt;P&gt;[EDIT:] Here it is:&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920732#M362641" target="_blank"&gt;https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920732#M362641&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 14:43:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920686#M362612</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-18T14:43:08Z</dc:date>
    </item>
    <item>
      <title>Re: How to check weather provided two strings are anagram  or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920712#M362626</link>
      <description>&lt;P&gt;You probably do need to worry about multi-byte characters.&amp;nbsp; Unless you can show that it is impossible to construct two different sets of unicode characters from the same set of bytes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example what if you had one string that had normal character X and also multi-byte character ZY.&amp;nbsp; And the other string had normal character Y and multi-byte character ZX.&amp;nbsp; They would each have the same 3 byte strings XYZ, but would not be anagrams when considering just the 2 character original strings.&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 13:23:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920712#M362626</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2024-03-18T13:23:27Z</dc:date>
    </item>
    <item>
      <title>Re: How to check weather provided two strings are anagram  or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920722#M362634</link>
      <description>&lt;P&gt;Yes, I'm looking for 3 byte UTF characters at the moment, which are:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;1110xxxx	10xxxxxx	10xxxxxx&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;so the second and third could be "swapped".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 13:37:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920722#M362634</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-18T13:37:42Z</dc:date>
    </item>
    <item>
      <title>Re: How to check weather provided two strings are anagram  or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920725#M362636</link>
      <description>&lt;P&gt;Here is an example which fails my code:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data x;
x="空";
y=char(x,1)!!char(x,3)!!char(x,2);
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 13:42:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920725#M362636</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-18T13:42:02Z</dc:date>
    </item>
    <item>
      <title>Re: How to check weather provided two strings are anagram  or not.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920732#M362641</link>
      <description>&lt;P&gt;Ok, this one fixes multi byte problem.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string_1 : $12. string_2 $12.;
datalines;
elbow below
brog grob
yet tey
abc efg
xxxxx xxxx
żółć ćółż
空手道 道手空
;
run;
data x;
  length string_1 string_2 $ 12;
  x="空";
  string_1=x;
  string_2=char(x,1)!!char(x,3)!!char(x,2);
  drop x;
run;

data have2;
  set have x;
run;
proc print;
run;

%let n=10; /* max number of letters */

data want;
  set have2;

  array str1_[&amp;amp;N.] $ 4. _temporary_;
  array str2_[&amp;amp;N.] $ 4. _temporary_;

  l1 = klength(string_1);
  l2 = klength(string_2);

  anagram=0;

  if l1 NE l2 then 
    do;
      output;
      if 0;
    end;

  do i = 1 to l1;
    str1_[i] = ksubstr(string_1,i,1);
    str2_[i] = ksubstr(string_2,i,1);
  end;

  call sortc(of str1_[*]);
  call sortc(of str2_[*]);

  anagram = (cats(of str1_[*]) = cats(of str2_[*]));
  output;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 18 Mar 2024 13:56:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-check-whether-two-strings-are-anagram-or-not/m-p/920732#M362641</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2024-03-18T13:56:54Z</dc:date>
    </item>
  </channel>
</rss>

