<?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 Exclusion Criteria for String Detection in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Exclusion-Criteria-for-String-Detection/m-p/825696#M326126</link>
    <description>&lt;P&gt;I apologize if a solution has already been presented for a similar question. I have tried using both of the below codes to detect specified strings of text and count the number of occurrences in a new column. The issue I am having is drugs like 'amphetamine' are still being counted for occurrences of 'methamphetamine'. Is there an alternative code that uses leading characters to exclude a string from being counted? I am not able to share the exact data but have included an example of how the 'identified' column appears and how substances are listed. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Code 1:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;data comb3;&lt;BR /&gt;set drugseizures;&lt;BR /&gt;if index(identified, 'methylenedioxymethamphetamine')&amp;gt; 0 then MDMA = 1;&lt;BR /&gt;else if index(identified, 'methylenedioxyamphetamine')&amp;gt;0 then MDA = 1;&lt;BR /&gt;else if index(identified, 'methamphetamine')&amp;gt;0 then methamphetamine = 1;&lt;BR /&gt;else if index(identified, 'amphetamine')&amp;gt;0 then amphetamine = 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Code 2:&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table comb5 as&lt;BR /&gt;select&lt;BR /&gt;*&lt;BR /&gt;&amp;nbsp;,case when identified contains 'amphetamine' and identified not like 'methamphetamine'&amp;nbsp;then 1 else 0 end as amphetamine&amp;nbsp;&lt;/P&gt;&lt;P&gt;,case when identified contains 'cannabidiol' and identified not like '%ocannabinol' then 1 else 0 end as cannabidiol&lt;/P&gt;&lt;P&gt;,case when (identified contains 'fentanyl') and (identified not like '%acetyl fentanyl%' or identified not like '%furanyl fentanyl%' or identified not like '%carfentanil%') then 1 else 0 end as fentanyl&lt;BR /&gt;,case when identified contains 'aspirin' then 1 else 0 end as aspirin&lt;BR /&gt;,case when identified contains 'methadone' then 1 else 0 end as methadone&lt;BR /&gt;,case when identified contains 'methylphenidate' then 1 else 0 end as methylphenidate&lt;BR /&gt;&lt;BR /&gt;from drugseizures&lt;BR /&gt;;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jul 2022 15:20:23 GMT</pubDate>
    <dc:creator>hc2</dc:creator>
    <dc:date>2022-07-27T15:20:23Z</dc:date>
    <item>
      <title>Exclusion Criteria for String Detection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclusion-Criteria-for-String-Detection/m-p/825696#M326126</link>
      <description>&lt;P&gt;I apologize if a solution has already been presented for a similar question. I have tried using both of the below codes to detect specified strings of text and count the number of occurrences in a new column. The issue I am having is drugs like 'amphetamine' are still being counted for occurrences of 'methamphetamine'. Is there an alternative code that uses leading characters to exclude a string from being counted? I am not able to share the exact data but have included an example of how the 'identified' column appears and how substances are listed. I am using SAS 9.4.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Code 1:&lt;/STRONG&gt;&lt;/U&gt;&lt;/P&gt;&lt;P&gt;data comb3;&lt;BR /&gt;set drugseizures;&lt;BR /&gt;if index(identified, 'methylenedioxymethamphetamine')&amp;gt; 0 then MDMA = 1;&lt;BR /&gt;else if index(identified, 'methylenedioxyamphetamine')&amp;gt;0 then MDA = 1;&lt;BR /&gt;else if index(identified, 'methamphetamine')&amp;gt;0 then methamphetamine = 1;&lt;BR /&gt;else if index(identified, 'amphetamine')&amp;gt;0 then amphetamine = 1;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;&lt;STRONG&gt;Sample Code 2:&lt;/STRONG&gt;&lt;/U&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table comb5 as&lt;BR /&gt;select&lt;BR /&gt;*&lt;BR /&gt;&amp;nbsp;,case when identified contains 'amphetamine' and identified not like 'methamphetamine'&amp;nbsp;then 1 else 0 end as amphetamine&amp;nbsp;&lt;/P&gt;&lt;P&gt;,case when identified contains 'cannabidiol' and identified not like '%ocannabinol' then 1 else 0 end as cannabidiol&lt;/P&gt;&lt;P&gt;,case when (identified contains 'fentanyl') and (identified not like '%acetyl fentanyl%' or identified not like '%furanyl fentanyl%' or identified not like '%carfentanil%') then 1 else 0 end as fentanyl&lt;BR /&gt;,case when identified contains 'aspirin' then 1 else 0 end as aspirin&lt;BR /&gt;,case when identified contains 'methadone' then 1 else 0 end as methadone&lt;BR /&gt;,case when identified contains 'methylphenidate' then 1 else 0 end as methylphenidate&lt;BR /&gt;&lt;BR /&gt;from drugseizures&lt;BR /&gt;;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 15:20:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclusion-Criteria-for-String-Detection/m-p/825696#M326126</guid>
      <dc:creator>hc2</dc:creator>
      <dc:date>2022-07-27T15:20:23Z</dc:date>
    </item>
    <item>
      <title>Re: Exclusion Criteria for String Detection</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Exclusion-Criteria-for-String-Detection/m-p/825705#M326128</link>
      <description>&lt;P&gt;Have you tried INDEXW instead of INDEX?&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jul 2022 15:46:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Exclusion-Criteria-for-String-Detection/m-p/825705#M326128</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-07-27T15:46:01Z</dc:date>
    </item>
  </channel>
</rss>

