<?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 extract first 5 words from string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280076#M269742</link>
    <description>&lt;P&gt;Will it always be 5 words or is that variable? Will you have addresses with less than 5 words?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you looked at compged or soundex functions?&lt;/P&gt;</description>
    <pubDate>Fri, 24 Jun 2016 20:32:57 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2016-06-24T20:32:57Z</dc:date>
    <item>
      <title>How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280055#M269739</link>
      <description>&lt;P&gt;How do I extract the first 5 words of a string? I have two address variables and I want to say "if first 5 words of address1=address2"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advandced!&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 19:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280055#M269739</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-06-24T19:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280063#M269740</link>
      <description>&lt;P&gt;What kind of "words" and "strings" are we talking about?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 20:14:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280063#M269740</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-24T20:14:17Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280068#M269741</link>
      <description>&lt;P&gt;An address like address1="4478 English Elm River Road unit 2" and address2=&lt;SPAN&gt;"&lt;/SPAN&gt;&lt;SPAN&gt;4478 English Elm &lt;/SPAN&gt;&lt;SPAN&gt;River Road unit 3&lt;/SPAN&gt;&lt;SPAN&gt;".&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I want to check that the first 5 words (i.e."4478 English Elm &lt;SPAN&gt;River Road") is the same in both address1 and address2.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 20:17:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280068#M269741</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-06-24T20:17:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280076#M269742</link>
      <description>&lt;P&gt;Will it always be 5 words or is that variable? Will you have addresses with less than 5 words?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have you looked at compged or soundex functions?&lt;/P&gt;</description>
      <pubDate>Fri, 24 Jun 2016 20:32:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280076#M269742</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-24T20:32:57Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280085#M269743</link>
      <description>&lt;P&gt;How about a function that counts the matching length, in words :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc fcmp outlib=sasuser.fcmp.character;
function matchWords(str1 $, str2 $);
j =  min(countw(str1), countw(str2));
do i = j to 1 by -1;
    if upcase(scan(str1, i)) ne upcase(scan(str2, i)) then j = i-1;
    end;
return (j);
endsub;
run;
quit;

options cmplib=sasuser.fcmp;

data have;
address1="4478 English Elm River Road unit 2"; 
address2="4478 English Elm River Road unit 3";
m = matchwords(address1, address2);
put _all_;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 24 Jun 2016 21:07:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280085#M269743</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2016-06-24T21:07:45Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280114#M269746</link>
      <description>&lt;P&gt;One option of how to address this. The code will return match='Y' if the first 5 words are the same. Not case sensitive and less than 5 words in string allowed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data sample;
  length address1 address2 $60;
  retain _prxid;
  if _n_=1 then
    _prxid=prxparse('s/^\s*(\w*)\s+(\w*)\s+(\w*)\s+(\w*)\s+(\w*)\s*.*/\U\1\2\3\4\5/o');
  address1="4478 English Elm River Road unit 2";
  address2="4478 English ELm River Road unit 3";
  if prxchange(_prxid,1,address1)=prxchange(_prxid,1,address2) then
    match='Y';
  else match='N';
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Jun 2016 06:12:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280114#M269746</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-06-25T06:12:41Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280116#M269747</link>
      <description>&lt;P&gt;You may have to register and log in to see this, but someone posted a macro to implement USPS abbreviations if that's helpful at all.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://listserv.uga.edu/cgi-bin/wa?A2=ind1606c&amp;amp;L=SAS-L&amp;amp;X=A8B00C8C9C39792B2F&amp;amp;Y=fkhurshed%40gmail.com&amp;amp;P=25962" target="_blank"&gt;https://listserv.uga.edu/cgi-bin/wa?A2=ind1606c&amp;amp;L=SAS-L&amp;amp;X=A8B00C8C9C39792B2F&amp;amp;Y=fkhurshed%40gmail.com&amp;amp;P=25962&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 25 Jun 2016 06:17:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280116#M269747</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-06-25T06:17:44Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280123#M269748</link>
      <description>&lt;PRE&gt;
data _null_;
address1="4478 English Elm River Road unit 2"; 
address2="4478 English Elm River Road unit 3";
call scan(address1,6,p1,l1,' ');
call scan(address2,6,p2,l2,' ');
five1=substr(address1,1,p1-2);
five2=substr(address2,1,p2-2);
if five1=five2 then put 'YES';
 else put 'NO';
run;

&lt;/PRE&gt;</description>
      <pubDate>Sat, 25 Jun 2016 08:41:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280123#M269748</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-06-25T08:41:18Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280178#M269749</link>
      <description>&lt;P&gt;And what happens if the address string is shorter?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;  address1="4478 English Elm Road";
  address2="9999 English Elm Road";&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 26 Jun 2016 02:06:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280178#M269749</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2016-06-26T02:06:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract first 5 words from string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280590#M269750</link>
      <description>&lt;P&gt;Life saver!!!! Thank you so much, works perfect!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/12447" target="_self"&gt;Patrick&lt;/A&gt;,&amp;nbsp;&lt;/SPAN&gt;I have another similar question you might know the solution to. How can I write code to check that address1 equals (is identical) to (address2 minus the last 2 words).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like&amp;nbsp;&lt;/P&gt;&lt;P&gt;address1=123 main st&lt;/P&gt;&lt;P&gt;address2= 123 main st bldg A&lt;/P&gt;</description>
      <pubDate>Mon, 27 Jun 2016 20:25:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-extract-first-5-words-from-string/m-p/280590#M269750</guid>
      <dc:creator>tropical_surfer</dc:creator>
      <dc:date>2016-06-27T20:25:49Z</dc:date>
    </item>
  </channel>
</rss>

