<?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: SAS compare if two strings have two or more words same in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75429#M21880</link>
    <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I wouldn't know of a SAS function doing this for you - but you could code it.&lt;BR /&gt;
&lt;BR /&gt;
Something like the code below could do:&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
length string1 string2 $60.;&lt;BR /&gt;
string1='Lycanthrope';&lt;BR /&gt;
string2='Luz vagaT ';&lt;BR /&gt;
output;&lt;BR /&gt;
string1='Come 883 Mai';&lt;BR /&gt;
string2='Come (OcraMiX_ dj) Mai';&lt;BR /&gt;
output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  length SubString1 $60.;&lt;BR /&gt;
&lt;BR /&gt;
  i=1;&lt;BR /&gt;
  counter=0;&lt;BR /&gt;
  SubString1=scan(String1,i,' ');&lt;BR /&gt;
&lt;BR /&gt;
  do while(SubString1 ne '');&lt;BR /&gt;
    counter +   find(String2,strip(SubString1))&amp;gt;0;&lt;BR /&gt;
    if counter=2 then leave;&lt;BR /&gt;
    i+1;&lt;BR /&gt;
    SubString1=scan(String1,i,' ');&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value counter&lt;BR /&gt;
    2='Match'&lt;BR /&gt;
    other='No Match'&lt;BR /&gt;
  ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=want;&lt;BR /&gt;
  format counter counter.;&lt;BR /&gt;
  var counter String1 String2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
You didn't tell us whether the sequence of words is relevant or not.&lt;BR /&gt;
&lt;BR /&gt;
If it is relevant then some additional logic would be necessary (i.e. you could define in the find function to only search the string beginning from a certain position - later than where you had already a hit).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
    <pubDate>Thu, 15 Apr 2010 13:48:47 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2010-04-15T13:48:47Z</dc:date>
    <item>
      <title>SAS compare if two strings have two or more words same</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75428#M21879</link>
      <description>Hi I have a data set&lt;BR /&gt;
&lt;BR /&gt;
input string1 $char60. string2 $char60.&lt;BR /&gt;
   datalines;                                                                                                         &lt;BR /&gt;
string1=Lycanthrope&lt;BR /&gt;
string2=Luz vagaT                                      &lt;BR /&gt;
output=no match&lt;BR /&gt;
string1=When Your Heart Stops Beating      &lt;BR /&gt;
string2=When your heart stops beating        &lt;BR /&gt;
output=match&lt;BR /&gt;
string1=155 44                                           string2=155 (+44)                                      &lt;BR /&gt;
output=match&lt;BR /&gt;
string1=Come Mai 883&lt;BR /&gt;
string2=Come Mai (OcraMiX_ dj) - 883         &lt;BR /&gt;
output=match&lt;BR /&gt;
&lt;BR /&gt;
I would like SAS to output if string1 has two or more words which match with string 2 a MATCH and if there are no words matching then it should display NO MATCH.&lt;BR /&gt;
&lt;BR /&gt;
I've tried the complev, compged, SPEDIS functions and none of these seem to be able to return the desired result.

Message was edited by: celendin</description>
      <pubDate>Thu, 15 Apr 2010 13:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75428#M21879</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-15T13:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: SAS compare if two strings have two or more words same</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75429#M21880</link>
      <description>Hi&lt;BR /&gt;
&lt;BR /&gt;
I wouldn't know of a SAS function doing this for you - but you could code it.&lt;BR /&gt;
&lt;BR /&gt;
Something like the code below could do:&lt;BR /&gt;
&lt;BR /&gt;
data have;&lt;BR /&gt;
length string1 string2 $60.;&lt;BR /&gt;
string1='Lycanthrope';&lt;BR /&gt;
string2='Luz vagaT ';&lt;BR /&gt;
output;&lt;BR /&gt;
string1='Come 883 Mai';&lt;BR /&gt;
string2='Come (OcraMiX_ dj) Mai';&lt;BR /&gt;
output;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
data want;&lt;BR /&gt;
  set have;&lt;BR /&gt;
  length SubString1 $60.;&lt;BR /&gt;
&lt;BR /&gt;
  i=1;&lt;BR /&gt;
  counter=0;&lt;BR /&gt;
  SubString1=scan(String1,i,' ');&lt;BR /&gt;
&lt;BR /&gt;
  do while(SubString1 ne '');&lt;BR /&gt;
    counter +   find(String2,strip(SubString1))&amp;gt;0;&lt;BR /&gt;
    if counter=2 then leave;&lt;BR /&gt;
    i+1;&lt;BR /&gt;
    SubString1=scan(String1,i,' ');&lt;BR /&gt;
  end;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc format;&lt;BR /&gt;
  value counter&lt;BR /&gt;
    2='Match'&lt;BR /&gt;
    other='No Match'&lt;BR /&gt;
  ;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
proc print data=want;&lt;BR /&gt;
  format counter counter.;&lt;BR /&gt;
  var counter String1 String2;&lt;BR /&gt;
run;&lt;BR /&gt;
&lt;BR /&gt;
You didn't tell us whether the sequence of words is relevant or not.&lt;BR /&gt;
&lt;BR /&gt;
If it is relevant then some additional logic would be necessary (i.e. you could define in the find function to only search the string beginning from a certain position - later than where you had already a hit).&lt;BR /&gt;
&lt;BR /&gt;
HTH&lt;BR /&gt;
Patrick</description>
      <pubDate>Thu, 15 Apr 2010 13:48:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75429#M21880</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2010-04-15T13:48:47Z</dc:date>
    </item>
    <item>
      <title>Re: SAS compare if two strings have two or more words same</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75430#M21881</link>
      <description>thanks Patrick that's exactly what i needed... thank you so much</description>
      <pubDate>Thu, 15 Apr 2010 21:52:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/SAS-compare-if-two-strings-have-two-or-more-words-same/m-p/75430#M21881</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2010-04-15T21:52:20Z</dc:date>
    </item>
  </channel>
</rss>

