<?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: Keep data only contains certain words but not anything else in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/340006#M272641</link>
    <description>&lt;P&gt;Given the example you posted, which records do you want to keep?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 10 Mar 2017 14:11:26 GMT</pubDate>
    <dc:creator>art297</dc:creator>
    <dc:date>2017-03-10T14:11:26Z</dc:date>
    <item>
      <title>Keep data only contains certain words but not anything else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/339878#M272640</link>
      <description>&lt;P&gt;I would like to search a string variable only contains certain words but not anything else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data would look like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Osteoarthritis (OA)
OA (Osteoarthritis)
OA Knee
Osteoarthritis Knee
OA + hands
Osteoarthritis, hands
OA , hip
OA
Knee OA&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;So I would like to keep the rows containing OA/Osteoarthritis, or OA/Osteo with knee, but get rid of everything else.&amp;nbsp;&lt;/P&gt;&lt;P&gt;OA/Osteo with knee is easy to keep, but I am in difficulty to keep those only having word OA/Osteoarthritis.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The variable is quite long and very messy, so impossible to list those I want to delete.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 04:42:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/339878#M272640</guid>
      <dc:creator>windlove</dc:creator>
      <dc:date>2017-03-10T04:42:26Z</dc:date>
    </item>
    <item>
      <title>Re: Keep data only contains certain words but not anything else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/340006#M272641</link>
      <description>&lt;P&gt;Given the example you posted, which records do you want to keep?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Art, CEO, AnalystFinder.com&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 14:11:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/340006#M272641</guid>
      <dc:creator>art297</dc:creator>
      <dc:date>2017-03-10T14:11:26Z</dc:date>
    </item>
    <item>
      <title>Re: Keep data only contains certain words but not anything else</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/340037#M272642</link>
      <description>&lt;P&gt;When describing character searches you must be very explicit as character variables may contain much junk.&lt;/P&gt;
&lt;P&gt;For instance you say you want to keep "rows containing OA/Osteoarthritis"&lt;/P&gt;
&lt;P&gt;NONE of your example data shows&amp;nbsp;OA&lt;FONT color="#ff00ff"&gt;&lt;STRONG&gt;/&lt;/STRONG&gt;&lt;/FONT&gt;Osteoarthritis (the / character ). Do you mean the string values OA and Osteoarthritis appearing as words (meaning OA by itself not as part of Oste&lt;FONT color="#ff0000"&gt;&lt;STRONG&gt;oa&lt;/STRONG&gt;&lt;/FONT&gt;rthritis or in the word oak)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For OA/Osteo&amp;nbsp; similar with the added bit of Osteo not appearing in compound? But when you say with knee, since none of your example shows Osteo do you mean "OA" or "Osteo" and "Knee"?&lt;/P&gt;
&lt;P&gt;Since your example data shows no instance of "Osteo" were you being lazy and not spelling "Osteoarthritis" completely? Spelling counts!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And will any of the words of interest be case sensitive: Find "Knee" but exclude "knee" (or vice versa)?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You know what you intend but computers are &lt;STRONG&gt;stupid&lt;/STRONG&gt; and must be given very explicit instructions. Without those explicit rules we could make some guesses but might very well miss some conditions that seem obvious to you but we are not mind readers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is a suggestion based on &lt;STRONG&gt;guesses&lt;/STRONG&gt;.&lt;/P&gt;
&lt;P&gt;assuming you want to match Knee or knee or kNee and similar&lt;/P&gt;
&lt;PRE&gt;data want;
   set have;
   if (findw(str,'OA',' (),:;','i')&amp;gt;0 and findw(str,'OSTEOARTHRITIS',' (),:;','i' ))
      or 
      ( (findw(str,'OA',' (),:;','i') or findw(str,'OSTEOARTHRITIS',' (),:;','i') ) 
         AND findw(str,'KNEE',' (),:;','i') )
      
   ;
run;&lt;/PRE&gt;
&lt;P&gt;where STR is the name of your variable with the text to search.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 10 Mar 2017 17:22:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-data-only-contains-certain-words-but-not-anything-else/m-p/340037#M272642</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-03-10T17:22:57Z</dc:date>
    </item>
  </channel>
</rss>

