<?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: IF statement that will delete a record if string contains &amp;quot;foo&amp;quot; in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538695#M16619</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the answer is to know something about your data.&amp;nbsp; You can construct problem strings for most simple solutions (which includes mine, just for the record):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WatchingTV&lt;/P&gt;
&lt;P&gt;Embowelling&lt;/P&gt;
&lt;P&gt;Bowel/Intestine&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;</description>
    <pubDate>Tue, 26 Feb 2019 16:29:40 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-02-26T16:29:40Z</dc:date>
    <item>
      <title>IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538673#M16614</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Let's say my data set is set up like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;study_id&amp;nbsp; &amp;nbsp; structure_id&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;BLADDER&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.&lt;/P&gt;&lt;P&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BOWEL&lt;/P&gt;&lt;P&gt;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; BOWEL_SMALL&lt;/P&gt;&lt;P&gt;5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GTV&lt;/P&gt;&lt;P&gt;6&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; GTV_small&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to delete records where structure_id contains "BOWEL" or "GTV".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried using this code:&lt;/P&gt;&lt;PRE&gt;data dvh_edited;
set dvh;
found=indexc(structure_id, "BOWEL", "GTV");
if found ^=0 then delete;
run;&lt;/PRE&gt;&lt;P&gt;But with that code it is looking for any letter in "BOWEL" or "GTV" so it's tagging many records.&amp;nbsp; I'm not that familiar with PROC SQL so I'd prefer to do this in a data step if it's fairly simple.&amp;nbsp; Thanks!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:07:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538673#M16614</guid>
      <dc:creator>jahanm</dc:creator>
      <dc:date>2019-02-26T16:07:26Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538683#M16615</link>
      <description>&lt;P&gt;Use the FIND function&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;if find(structure_id, "BOWEL", "i") &amp;gt; 0 or find(structure_id,"GTV","i") &amp;gt; 0 then delete;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:15:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538683#M16615</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-26T16:15:02Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538684#M16616</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input study_id    structure_id  : $13.;
cards;
1                 BLADDER
2                 .
3                  BOWEL
4                  BOWEL_SMALL
5                  GTV
6                  GTV_small
;

data want;
set have;
found=findw(strip(structure_id), "BOWEL",'_') or findw(strip(structure_id), "GTV",'_');
if found ^=0 then delete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:15:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538684#M16616</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-02-26T16:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538685#M16617</link>
      <description>&lt;P&gt;It's easy if you are willing to code each word separately:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if findw(structure_id, 'GTV', , '_ ,' , 'I') then delete;&lt;/P&gt;
&lt;P&gt;if findw(structure_id, 'BOWEL', , '_ ,' , 'I') then delete;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming I got all the pieces of this in the right places:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The third parameter is starting position so can default to beginning of the string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fourth parameter is a list of word delimiters.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The fifth parameter asks that case be ignored, so these are both to be deleted:&amp;nbsp; GTV and gtv&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note that this is probably more what you want, rather than INDEX or FIND.&amp;nbsp; You probably don't want to delete observations that contain "HGTV", or "EMBOWEL".&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hmmm......&amp;nbsp; 3 responses in the first 10 minutes.&amp;nbsp; Might be time for me to shut down the computer and go to lunch.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:21:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538685#M16617</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-26T16:21:26Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538690#M16618</link>
      <description>&lt;P&gt;FINDW finds words, if the input text string is GTVsmall without the underscore, FINDW will not find it. I don't see a problem using FIND instead of FINDW.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:23:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538690#M16618</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-26T16:23:19Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538695#M16619</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I think the answer is to know something about your data.&amp;nbsp; You can construct problem strings for most simple solutions (which includes mine, just for the record):&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;WatchingTV&lt;/P&gt;
&lt;P&gt;Embowelling&lt;/P&gt;
&lt;P&gt;Bowel/Intestine&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;</description>
      <pubDate>Tue, 26 Feb 2019 16:29:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538695#M16619</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-02-26T16:29:40Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538697#M16620</link>
      <description>&lt;P&gt;Good point.&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 16:33:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538697#M16620</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-02-26T16:33:19Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538823#M16621</link>
      <description>&lt;P&gt;Unfortunately the structure_id variable is human-entered freetext so I actually do run into the problem you stated.&amp;nbsp; There are some variables "GTVp" that I also want to eliminate, and the findw code earlier doesn't seem to filter variants like that.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Feb 2019 21:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/538823#M16621</guid>
      <dc:creator>jahanm</dc:creator>
      <dc:date>2019-02-26T21:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: IF statement that will delete a record if string contains "foo"</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/539186#M16627</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/263090"&gt;@jahanm&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Unfortunately the structure_id variable is human-entered freetext so I actually do run into the problem you stated.&amp;nbsp; There are some variables "GTVp" that I also want to eliminate, and the findw code earlier doesn't seem to filter variants like that.&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&lt;BR /&gt;Regular expressions allow you to search for text patterns - you just need to be able to formulate the rules for these patterns.&lt;/P&gt;
&lt;P&gt;Below RegEx will match any string with &lt;EM&gt;bowel&lt;/EM&gt; or &lt;EM&gt;gtv&lt;/EM&gt; in it. But using a RegEx would also allow you to search for a pattern like a word consisting of GTV plus max. one additional letter.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input study_id structure_id : $13.;
  cards;
1 BLADDER
2 .
3 BOWEL
4 BOWEL_SMALL
5 GTV
6 GTV_small
;

data want;
  set have;
  if prxmatch('/bowel|gtv/oi',structure_id)&amp;gt;0 then delete;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 27 Feb 2019 23:30:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/IF-statement-that-will-delete-a-record-if-string-contains-quot/m-p/539186#M16627</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-02-27T23:30:15Z</dc:date>
    </item>
  </channel>
</rss>

