<?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 words in a variable in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85854#M24540</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We can try index or find but in huge datasets try not using If condition instead use where for faster application as in the following code;-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table col_data as&lt;/P&gt;&lt;P&gt;select memname from&lt;/P&gt;&lt;P&gt;sashelp.vtable&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set Col_data;&lt;/P&gt;&lt;P&gt;where index(upcase(memname),upcase("attribute"))&amp;gt;0; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 30 May 2013 07:36:09 GMT</pubDate>
    <dc:creator>NishunkSaxena</dc:creator>
    <dc:date>2013-05-30T07:36:09Z</dc:date>
    <item>
      <title>searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85846#M24532</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am wondering how I can do the following:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a data set with about 6000 rows of information - each field contains a string (something like this -&amp;gt; This is a sample text string)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was wondering what I can do to "search" all the rows of information for specific key words and then only keep those in my new smaller data set.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I want to say: if the words "this" "now" "then" appear in the column then keep that row or identify it somehow.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Any sample codes would be greatly appreciated!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 16:25:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85846#M24532</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2013-05-24T16:25:33Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85847#M24533</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try the find() and index() functions. &lt;/P&gt;&lt;P&gt;There's also the PRX functions if you're interested in learning them. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 16:28:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85847#M24533</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-05-24T16:28:35Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85848#M24534</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I tried scan and index - both give me this error:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;function call has too many arguments&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a bunch of keywords I am searching for in my code. Like this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;got_value=SCAN(var_1,"key1","key2" etc.);&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 16:33:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85848#M24534</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2013-05-24T16:33:04Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85849#M24535</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I think only PRX functions will allow you to have multiple keywords in a single function.&lt;/P&gt;&lt;P&gt;Scan is used to substr or subset a sentence though, not search through it.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if find(var_1, "word1")&amp;gt;0 or&lt;/P&gt;&lt;P&gt;find(var_1, "word2")&amp;gt;0 then got_value=1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Is one way, but probably not optimal. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 16:35:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85849#M24535</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-05-24T16:35:37Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85850#M24536</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;You may want the FINDW, find word, function. And you can generally search for only one value at a time.&lt;/P&gt;&lt;P&gt;Also unless you are 100 percent positive that the words are always in the same case you may want to either UPCASE or LOWCASE the searched string and make sure the value searched for is in the same case.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;findword1 = (findw(upcase(string), 'WORD')&amp;gt;0);&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;scan PULLS a word by position in a string.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 16:40:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85850#M24536</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-05-24T16:40:05Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85851#M24537</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I looked up prx, but cannot get it to work. This sample I modified seems to be what I need, but it is not working:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __jive_macro_name="quote" class="jive_text_macro jive_macro_quote" modifiedtitle="true"&gt;
&lt;P&gt;data _null_;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if _N_ = 1 then &lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain patternID;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; /* The i option specifies a case insensitive search. */&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; pattern = "/Mount|TGH|Joe|Michael|Sunny|Toro|Bay|Brid|Provi/i";&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; patternID = prxparse(pattern);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;P&gt;input service_provider $90.;&lt;/P&gt;
&lt;P&gt;call prxsubstr(patternID, service_provider, position);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if position ^= 0 then&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; match = substr(service_provider, position);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; put match:$QUOTE. "found in " service_provider:$QUOTE.;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 16:49:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85851#M24537</guid>
      <dc:creator>vomer</dc:creator>
      <dc:date>2013-05-24T16:49:19Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85852#M24538</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try INDEXW function.&lt;/P&gt;&lt;P&gt;So if the list is short you can just type them all out.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;if indexw(upcase(string),'WORD1')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;or indexw(upcase(string),'WORD2')&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;...&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'courier new', courier;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 24 May 2013 17:10:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85852#M24538</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2013-05-24T17:10:33Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85853#M24539</link>
      <description>&lt;P&gt;&lt;EM&gt;Editor's note: Thanks for all the contributions, some great ideas.&amp;nbsp; This is a good case for PRX functions and this answer illustrates it's ability.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PRX to the rescue!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data have;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;length string $100;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;input string &amp;amp;;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;datalines;&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;This is a sample text string&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;That is another string&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;And then a last string&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;data want;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;/* Search string for : &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; a word boundary, &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then the first string or the second string or ... or the last string, &lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; then a word boundary&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; make the search case insensitive&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&amp;nbsp; compile the pattern only once */&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;set have(where=(prxmatch("/\b(this|now|then)\b/io", string)));&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;proc print noobs; run;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PG&lt;/P&gt;</description>
      <pubDate>Wed, 30 Aug 2017 15:10:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85853#M24539</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-08-30T15:10:08Z</dc:date>
    </item>
    <item>
      <title>Re: searching words in a variable</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85854#M24540</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;We can try index or find but in huge datasets try not using If condition instead use where for faster application as in the following code;-&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table col_data as&lt;/P&gt;&lt;P&gt;select memname from&lt;/P&gt;&lt;P&gt;sashelp.vtable&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data final;&lt;/P&gt;&lt;P&gt;set Col_data;&lt;/P&gt;&lt;P&gt;where index(upcase(memname),upcase("attribute"))&amp;gt;0; run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 May 2013 07:36:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/searching-words-in-a-variable/m-p/85854#M24540</guid>
      <dc:creator>NishunkSaxena</dc:creator>
      <dc:date>2013-05-30T07:36:09Z</dc:date>
    </item>
  </channel>
</rss>

