<?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 Find two words in text field in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733058#M228436</link>
    <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find all instances when two words are present in a text field.&lt;/P&gt;&lt;P&gt;In MS SQL&amp;nbsp; I can use&amp;nbsp;CONTAINS(t1.NOTES, 'NEAR((Apples, Red),3)'), meaning the words Apples and Red are located near each other.&lt;/P&gt;&lt;P&gt;When I try this in SAS EG 71. I get&amp;nbsp;ERROR: Function CONTAINS could not be located.&lt;/P&gt;&lt;P&gt;I also tried&amp;nbsp;prxmatch("!(Apples|Red)!i", t1.NOTES)&amp;gt; 0, however either word shows up in the results.&lt;/P&gt;&lt;P&gt;So if we have&amp;nbsp;&lt;BR /&gt;1 - Apple Granny Green&lt;/P&gt;&lt;P&gt;2 - Apple Spartan Red&lt;/P&gt;&lt;P&gt;3 - Apple Jazz Red&lt;/P&gt;&lt;P&gt;4 - Apple Yellow Delicious&lt;/P&gt;&lt;P&gt;#2 and #3 are valid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am doing this in Proc SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 12 Apr 2021 18:01:43 GMT</pubDate>
    <dc:creator>R_Auger</dc:creator>
    <dc:date>2021-04-12T18:01:43Z</dc:date>
    <item>
      <title>Find two words in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733058#M228436</link>
      <description>&lt;P&gt;Hi&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to find all instances when two words are present in a text field.&lt;/P&gt;&lt;P&gt;In MS SQL&amp;nbsp; I can use&amp;nbsp;CONTAINS(t1.NOTES, 'NEAR((Apples, Red),3)'), meaning the words Apples and Red are located near each other.&lt;/P&gt;&lt;P&gt;When I try this in SAS EG 71. I get&amp;nbsp;ERROR: Function CONTAINS could not be located.&lt;/P&gt;&lt;P&gt;I also tried&amp;nbsp;prxmatch("!(Apples|Red)!i", t1.NOTES)&amp;gt; 0, however either word shows up in the results.&lt;/P&gt;&lt;P&gt;So if we have&amp;nbsp;&lt;BR /&gt;1 - Apple Granny Green&lt;/P&gt;&lt;P&gt;2 - Apple Spartan Red&lt;/P&gt;&lt;P&gt;3 - Apple Jazz Red&lt;/P&gt;&lt;P&gt;4 - Apple Yellow Delicious&lt;/P&gt;&lt;P&gt;#2 and #3 are valid&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am doing this in Proc SQL.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 18:01:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733058#M228436</guid>
      <dc:creator>R_Auger</dc:creator>
      <dc:date>2021-04-12T18:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Find two words in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733086#M228449</link>
      <description>&lt;P&gt;Here's one way to do it:&amp;nbsp;&lt;BR /&gt;First data step sets up your test data&lt;BR /&gt;Then 2 examples using data step and PROC SQL&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data got ;
	infile cards ;
	input string $30. ;
cards;
Apple Granny Green
Apple Spartan Red
Apple Jazz Red
Apple Yellow Delicious
Oranges and Pears
;

data want ;
	set got ;
	x=prxmatch('/Red/',string) ;
	y=prxmatch('/Apple/',string) ;
	if x and y then 
		put "Red Apple - " string ;
	else
	if x then
		put "Red Only - " string ;
	else
	if y then
		put "Apple Only - " string ;
	else 
		put "None - " string ;

run ;&lt;BR /&gt;&lt;BR /&gt;proc sql ;&lt;BR /&gt;  select *&lt;BR /&gt;  from got&lt;BR /&gt;  where prxmatch('/Red/',string) and prxmatch('/Apple/',string) &lt;BR /&gt;;&lt;BR /&gt;quit ;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 12 Apr 2021 19:30:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733086#M228449</guid>
      <dc:creator>AMSAS</dc:creator>
      <dc:date>2021-04-12T19:30:22Z</dc:date>
    </item>
    <item>
      <title>Re: Find two words in text field</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733092#M228453</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/230560"&gt;@R_Auger&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The 'e' modifier of the &lt;A href="https://documentation.sas.com/?cdcId=pgmsascdc&amp;amp;cdcVersion=9.4_3.5&amp;amp;docsetId=lefunctionsref&amp;amp;docsetTarget=p16rdsa30vmm43n1ej4936nwa01t.htm&amp;amp;locale=en" target="_blank" rel="noopener"&gt;FINDW function&lt;/A&gt;&amp;nbsp;in conjunction with absolute differences of word positions could be useful to implement something similar to the proximity term NEAR in MS SQL.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Example:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input n text $50.;
cards;
1 Apple Granny Green
2 Apple Spartan Red
3 Apple Jazz Red
4 Apple Yellow Delicious
5 apple cool Jazz Juicy Dark Red Fruit
6 Apple cool Juicy Dark red Fruit
7 big red super fresh apple
8 red really red super fresh apple
;

proc sql;
create table want(drop=_:) as
select *, findw(text,'apple', ' ', 'ei') as _p1,
          findw(text,'red',   ' ', 'ei') as _p2
from have
having _p1 &amp;amp; _p2 &amp;amp; abs(_p1-_p2)&amp;lt;5;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Result:&lt;/P&gt;
&lt;PRE&gt;n    text

2    Apple Spartan Red
3    Apple Jazz Red
6    Apple cool Juicy Dark red Fruit
7    big red super fresh apple&lt;/PRE&gt;
&lt;P&gt;Item 8 shows the limitation of FINDW, though: It finds only the &lt;EM&gt;first&lt;/EM&gt; occurrence of a word so that duplicates could be a problem. Here, &lt;FONT face="courier new,courier"&gt;_p1=6&lt;/FONT&gt; and &lt;FONT face="courier new,courier"&gt;_p2=&lt;STRONG&gt;1&lt;/STRONG&gt;&lt;/FONT&gt; violate the proximity condition.&lt;/P&gt;</description>
      <pubDate>Mon, 12 Apr 2021 19:42:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-two-words-in-text-field/m-p/733092#M228453</guid>
      <dc:creator>FreelanceReinh</dc:creator>
      <dc:date>2021-04-12T19:42:34Z</dc:date>
    </item>
  </channel>
</rss>

