<?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: Flag strings that have words in common in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595295#M34875</link>
    <description>&lt;P&gt;Welcome to the SAS Community! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input col1 $ 1-24 col2 $ 27-43;
infile datalines dlm='|';
datalines;
London, United Kingdom  | British Columbia
Mexico City             | New Mexico      
Boston                  | New York        
United States of America| South America   
;

data want(drop=i);
    set have;
    flag=0;
    do i=1 to countw(col2);
      if findw(col1, scan(col2, i, ' '), ' ', 'sit') then do;
        flag=1;
      end;    
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;col1                      col2             flag
London, United Kingdom    British Columbia 0
Mexico City               New Mexico       1
Boston                    New York         0
United States of America  South America    1&lt;/PRE&gt;</description>
    <pubDate>Thu, 10 Oct 2019 09:21:14 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2019-10-10T09:21:14Z</dc:date>
    <item>
      <title>Flag strings that have words in common</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595294#M34874</link>
      <description>&lt;P&gt;I have a dataset with two string columns that each contain multiple words (locations, for example).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rowwise, I want to flag observations where the two strings have any words in common.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Does anyone know a way to achieve this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example strings and expected output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;col1 | col2 | flag&lt;/P&gt;&lt;P&gt;London,&amp;nbsp;United Kingdom | British Columbia&amp;nbsp; | 0&lt;/P&gt;&lt;P&gt;Mexico City | New Mexico | 1&lt;/P&gt;&lt;P&gt;Boston |&amp;nbsp;New York | 0&lt;/P&gt;&lt;P&gt;United States of America | South America | 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2019 09:12:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595294#M34874</guid>
      <dc:creator>astrand</dc:creator>
      <dc:date>2019-10-10T09:12:44Z</dc:date>
    </item>
    <item>
      <title>Re: Flag strings that have words in common</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595295#M34875</link>
      <description>&lt;P&gt;Welcome to the SAS Community! &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You can do something like this&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input col1 $ 1-24 col2 $ 27-43;
infile datalines dlm='|';
datalines;
London, United Kingdom  | British Columbia
Mexico City             | New Mexico      
Boston                  | New York        
United States of America| South America   
;

data want(drop=i);
    set have;
    flag=0;
    do i=1 to countw(col2);
      if findw(col1, scan(col2, i, ' '), ' ', 'sit') then do;
        flag=1;
      end;    
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;col1                      col2             flag
London, United Kingdom    British Columbia 0
Mexico City               New Mexico       1
Boston                    New York         0
United States of America  South America    1&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2019 09:21:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595295#M34875</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2019-10-10T09:21:14Z</dc:date>
    </item>
    <item>
      <title>Re: Flag strings that have words in common</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595303#M34876</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/258806"&gt;@astrand&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is something you can try. please note that it is case sensitive.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input col1 $ 1-24 col2 $ 26-42;
	cards;
London, United Kingdom   British Columbia
Mexico City              New Mexico
Boston                   New York
	;
run;

/*Counts the max number of words in a the first column*/
proc sql noprint;
	select max(countw(col1))
	into: maxword
	from have;
quit;

data want;
	set have;
	
	array wordloc (&amp;amp;maxword) $ ;
	array flagloc (&amp;amp;maxword)   ;
	
	do i=1 to &amp;amp;maxword;
		wordloc(i) = scan(col1,i);
		if index(col2,trim(wordloc(i)))&amp;gt;0 and wordloc(i) ne "" then flagloc(i)=1;
	end;
		flag = sum(of flagloc(*));
		if flag = . then flag =0;
	drop i;
	
run;

proc print data=want;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 10 Oct 2019 10:00:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595303#M34876</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2019-10-10T10:00:44Z</dc:date>
    </item>
    <item>
      <title>Re: Flag strings that have words in common</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595344#M34877</link>
      <description>A tip to speed up the process...&lt;BR /&gt;&lt;BR /&gt;Stop processing once you find a match.  For example, if you have this statement:&lt;BR /&gt;&lt;BR /&gt;do i=1 to countw(col2) ;&lt;BR /&gt;&lt;BR /&gt;switch to:&lt;BR /&gt;&lt;BR /&gt;do i=1 to countw(col2) until (flag=1) ;</description>
      <pubDate>Thu, 10 Oct 2019 12:00:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595344#M34877</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-10-10T12:00:40Z</dc:date>
    </item>
    <item>
      <title>Re: Flag strings that have words in common</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595382#M34878</link>
      <description>This worked perfectly. Thank you!</description>
      <pubDate>Thu, 10 Oct 2019 13:27:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Flag-strings-that-have-words-in-common/m-p/595382#M34878</guid>
      <dc:creator>astrand</dc:creator>
      <dc:date>2019-10-10T13:27:42Z</dc:date>
    </item>
  </channel>
</rss>

