<?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: Check if a string variable includes any of multiple words? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620769#M182466</link>
    <description>&lt;P&gt;Try PRXMATCH &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;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    string='an apple';
    if prxmatch('/apple|orange/', string) then fruit=1;
    put fruit=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 29 Jan 2020 08:41:06 GMT</pubDate>
    <dc:creator>PeterClemmensen</dc:creator>
    <dc:date>2020-01-29T08:41:06Z</dc:date>
    <item>
      <title>Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620768#M182465</link>
      <description>&lt;P&gt;I would like to make a code to check if a string variable includes any of multiple words (e.g., any of "apple" or "orange"). Can I simplify the below code because my list of target words is more than ten (apple, orange, blueberry, etc.)? The variable, NAME, can include some strings including "orange". An example is "two apples."&amp;nbsp; In this case, I would like to give 1 to the fruit variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if 	index(lowcase(name), "apple") or index(lowcase(name), "orange") then fruit= 1; 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 08:33:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620768#M182465</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2020-01-29T08:33:45Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620769#M182466</link>
      <description>&lt;P&gt;Try PRXMATCH &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;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
    string='an apple';
    if prxmatch('/apple|orange/', string) then fruit=1;
    put fruit=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 08:41:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620769#M182466</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-29T08:41:06Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620773#M182467</link>
      <description>&lt;P&gt;Sorry for the confusion. In the piece of my code, "name" was the column in my dataset. To be clearer, the below is the code I can make. But I would like to get it simplified further (perhaps a code including "audi", "acura", "volvo"?).&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;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data temp; set sashelp.cars;
	if index(lowcase(make), "audi")&amp;gt;0 or 	
		index(lowcase(make), "acura")&amp;gt;0 or 
		index(lowcase(make), "volvo")&amp;gt;0  
	then dum= 1; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 09:10:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620773#M182467</guid>
      <dc:creator>braam</dc:creator>
      <dc:date>2020-01-29T09:10:43Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620774#M182468</link>
      <description>&lt;P&gt;Same principle. See the code below. The &lt;STRONG&gt;i&amp;nbsp;&lt;/STRONG&gt;means that the text search is case insensitive&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data temp;
    set sashelp.cars;
    if prxmatch('/audi|acura|volvo/i', make) then dum=1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 29 Jan 2020 09:13:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/620774#M182468</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2020-01-29T09:13:27Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/621067#M182533</link>
      <description>&lt;P&gt;Better add '\b'.&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;prxmatch&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'/\b(apple|orange|banana)\b/'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt; string&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; &lt;SPAN class="token keyword"&gt;then&lt;/SPAN&gt; fruit&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, 30 Jan 2020 07:24:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/621067#M182533</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2020-01-30T07:24:30Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/806821#M317959</link>
      <description>That was perfect, thank you!</description>
      <pubDate>Fri, 08 Apr 2022 17:35:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/806821#M317959</guid>
      <dc:creator>dknochen</dc:creator>
      <dc:date>2022-04-08T17:35:27Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/806843#M317969</link>
      <description>What about "apples, oranges and bananas"?</description>
      <pubDate>Fri, 08 Apr 2022 20:28:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/806843#M317969</guid>
      <dc:creator>average_joe</dc:creator>
      <dc:date>2022-04-08T20:28:40Z</dc:date>
    </item>
    <item>
      <title>Re: Check if a string variable includes any of multiple words?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/806915#M318011</link>
      <description>&lt;PRE&gt;data _null_;
string="apples, oranges and bananas";
if prxmatch('/\b(apple|orange|banana)s?\b/', string) then fruit=1;
put string= fruit=;

call missing(of _all_);

string="apple, orange and banana";
if prxmatch('/\b(apple|orange|banana)s?\b/', string) then fruit=1;
put string= fruit=;
run;&lt;/PRE&gt;</description>
      <pubDate>Sat, 09 Apr 2022 10:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Check-if-a-string-variable-includes-any-of-multiple-words/m-p/806915#M318011</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-04-09T10:03:16Z</dc:date>
    </item>
  </channel>
</rss>

