<?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: Searching if a phrase exists between two variables in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395832#M95533</link>
    <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE;

MATCH=0;

NEW_A=compbl(tranwrd(tranwrd(A,",","-"),"-"," "));
NEW_B=compbl(tranwrd(tranwrd(B,",","-"),"-"," "));

if NEW_A=NEW_B then MATCH=1;

if MATCH=0 then do;
  COUNT_WORDS_NEW_A=countw(right(NEW_A),"");
  COUNT_WORDS_NEW_B=countw(right(NEW_B),"");

if COUNT_WORDS_NEW_A&amp;lt;=COUNT_WORDS_NEW_B then
  MATCH = NEW_A=substr(NEW_B,1,length(NEW_A);
else if COUNT_WORDS_NEW_B &amp;lt; COUNT_WORDS_NEW_A then
  MATCH = NEW_B=substr(NEW_A,1,length(NEW_B);
end;
run;

*Do google the SAS functions i used such as TRANWRD, COMPBL, COUNTW, SUBSTR, LENGTH.;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
    <pubDate>Thu, 14 Sep 2017 01:49:45 GMT</pubDate>
    <dc:creator>ShiroAmada</dc:creator>
    <dc:date>2017-09-14T01:49:45Z</dc:date>
    <item>
      <title>Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395812#M95521</link>
      <description>&lt;P&gt;Hi ,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I&amp;nbsp;am working on a dataset where I am supposed to compare two &amp;nbsp;variables to check if a phrase exists in one of the variables or not. I tried using index function and find function .Both the functions work if there a one-to-one match , I want SAS to tell even if there is that particular phrase in the variable .Ie , I want to check from my below example , variable A phrase is present in Variable b : &amp;nbsp;Below is the example of what I want :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;a&lt;/TD&gt;&lt;TD&gt;b&lt;/TD&gt;&lt;TD&gt;INDEX Function Result&lt;/TD&gt;&lt;TD&gt;Expected Result&amp;nbsp;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Left ICA&lt;/TD&gt;&lt;TD&gt;Left ICA&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;Match&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Left Middle cere - M1&lt;/TD&gt;&lt;TD&gt;Left Middle cere - M1&lt;/TD&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Match&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Right Verte&lt;/TD&gt;&lt;TD&gt;Right Verte,Right Verte, mid cervi&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Match&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Right Middle cere - M1,Right Supra ICA&lt;/TD&gt;&lt;TD&gt;Right Middle cere - M1&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Match&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Midline Basilar trunk&lt;/TD&gt;&lt;TD&gt;Midline Basilar trunk,Right Verte&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;Match&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Right Verte&lt;/TD&gt;&lt;TD&gt;Left Verte&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;No Matching Data&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Left Middle cere - M1&lt;/TD&gt;&lt;TD&gt;Left Verte&lt;/TD&gt;&lt;TD&gt;0&lt;/TD&gt;&lt;TD&gt;&lt;SPAN&gt;No Matching Data&lt;/SPAN&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there an other SAS function or method can I use?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope I phrased my question correctly,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks In Advance !!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 23:40:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395812#M95521</guid>
      <dc:creator>desas</dc:creator>
      <dc:date>2017-09-13T23:40:59Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395814#M95522</link>
      <description>&lt;P&gt;/*untested*/&lt;/P&gt;&lt;P&gt;Try eqt operator&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table want as&lt;/P&gt;&lt;P&gt;select *&lt;/P&gt;&lt;P&gt;from have&lt;/P&gt;&lt;P&gt;where a eqt b;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Wed, 13 Sep 2017 23:48:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395814#M95522</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-09-13T23:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395815#M95523</link>
      <description>Thanks for the reply ! , But it does not work. :(, Yet I am glad to learn that there is an 'EQT' operator in PROC SQL</description>
      <pubDate>Wed, 13 Sep 2017 23:56:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395815#M95523</guid>
      <dc:creator>desas</dc:creator>
      <dc:date>2017-09-13T23:56:38Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395817#M95524</link>
      <description>&lt;P&gt;Can you show your code?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Did you use any of the modifiers to ignore case?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And I'm assuming you're using FINDW and INDEXW even though you say FIND/INDEX.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 00:04:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395817#M95524</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-09-14T00:04:22Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395821#M95527</link>
      <description>&lt;P&gt;i think this gives you the expected output - it searches both strings for the presence of the other&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	length str1 $100 str2 $100;
	infile datalines dlm="~";
	input str1 $ str2 $;
	datalines;
Left ICA~Left ICA
Left Middle cere - M1~Left Middle cere - M1
Right Verte~Right Verte,Right Verte, mid cervi
Right Middle cere - M1,Right Supra ICA~Right Middle cere - M1
Midline Basilar trunk~Midline Basilar trunk,Right Verte
Right Verte~Left Verte
Left Middle cere - M1~Left Verte
;
run;

data want;
	set have;
	if find(strip(str2),strip(str1)) or find(strip(str1),strip(str2)) then flag=1;
	else flag=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 00:12:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395821#M95527</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2017-09-14T00:12:24Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395831#M95532</link>
      <description>&lt;P&gt;Good idea. &amp;nbsp;One more thing to consider: &amp;nbsp;if upper vs. lower case should still be a match, and the 'i' modifier:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;	&lt;SPAN class="token keyword"&gt;if&lt;/SPAN&gt; &lt;SPAN class="token function"&gt;find&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;str2&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;str1&lt;SPAN class="token punctuation"&gt;), 'i'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; or &lt;SPAN class="token function"&gt;find&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;str1&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;strip&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;str2&lt;SPAN class="token punctuation"&gt;), 'i'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; flag&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;1&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 14 Sep 2017 01:22:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395831#M95532</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-09-14T01:22:35Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395832#M95533</link>
      <description>&lt;P&gt;Try this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data WANT;
  set HAVE;

MATCH=0;

NEW_A=compbl(tranwrd(tranwrd(A,",","-"),"-"," "));
NEW_B=compbl(tranwrd(tranwrd(B,",","-"),"-"," "));

if NEW_A=NEW_B then MATCH=1;

if MATCH=0 then do;
  COUNT_WORDS_NEW_A=countw(right(NEW_A),"");
  COUNT_WORDS_NEW_B=countw(right(NEW_B),"");

if COUNT_WORDS_NEW_A&amp;lt;=COUNT_WORDS_NEW_B then
  MATCH = NEW_A=substr(NEW_B,1,length(NEW_A);
else if COUNT_WORDS_NEW_B &amp;lt; COUNT_WORDS_NEW_A then
  MATCH = NEW_B=substr(NEW_A,1,length(NEW_B);
end;
run;

*Do google the SAS functions i used such as TRANWRD, COMPBL, COUNTW, SUBSTR, LENGTH.;

&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope it helps.&lt;/P&gt;</description>
      <pubDate>Thu, 14 Sep 2017 01:49:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/395832#M95533</guid>
      <dc:creator>ShiroAmada</dc:creator>
      <dc:date>2017-09-14T01:49:45Z</dc:date>
    </item>
    <item>
      <title>Re: Searching if a phrase exists between two variables</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/396437#M95704</link>
      <description>&lt;P&gt;Thanks All !!! &amp;nbsp;This was very helpful !!!!!!&lt;/P&gt;</description>
      <pubDate>Fri, 15 Sep 2017 17:46:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Searching-if-a-phrase-exists-between-two-variables/m-p/396437#M95704</guid>
      <dc:creator>desas</dc:creator>
      <dc:date>2017-09-15T17:46:33Z</dc:date>
    </item>
  </channel>
</rss>

