<?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: More efficient way to search for strings in a character field? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76911#M16617</link>
    <description>The INDEX function appears to be the most efficient, as compared to the recently added FIND function.  &lt;BR /&gt;
&lt;BR /&gt;
Also, using your coding example, I also tested using OR condition rather than IF THEN ELSE  logic and again INDEX was more efficient, say with a 1 million DO loop iteration with an OUTPUT.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
    <pubDate>Thu, 12 Mar 2009 14:34:49 GMT</pubDate>
    <dc:creator>sbb</dc:creator>
    <dc:date>2009-03-12T14:34:49Z</dc:date>
    <item>
      <title>More efficient way to search for strings in a character field?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76910#M16616</link>
      <description>I'm currently using the code below to search field ABC for one of several text strings; if any of them appear, I set NEW_FIELD to a common result.  Is there a better way to do this?  In plain english, I'm looking for a statement that says, if ABC contains any of the following:  'STRING1',  . . . 'STRING6' then NEW_FIELD = 'RESULT1'&lt;BR /&gt;
&lt;BR /&gt;
IF      INDEX(ABC, 'STRING1') &amp;gt; 0 THEN NEW_FIELD = 'RESULT1';&lt;BR /&gt;
ELSE IF INDEX(ABC, 'STRING2') &amp;gt; 0 THEN NEW_FIELD = 'RESULT1';&lt;BR /&gt;
ELSE IF INDEX(ABC, 'STRING3') &amp;gt; 0 THEN NEW_FIELD = 'RESULT1';&lt;BR /&gt;
ELSE IF INDEX(ABC, 'STRING4') &amp;gt; 0 THEN NEW_FIELD = 'RESULT1';&lt;BR /&gt;
ELSE IF INDEX(ABC, 'STRING5') &amp;gt; 0 THEN NEW_FIELD = 'RESULT1';&lt;BR /&gt;
ELSE IF INDEX(ABC, 'STRING6') &amp;gt; 0 THEN NEW_FIELD = 'RESULT1';</description>
      <pubDate>Thu, 12 Mar 2009 13:50:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76910#M16616</guid>
      <dc:creator>CaesarS</dc:creator>
      <dc:date>2009-03-12T13:50:55Z</dc:date>
    </item>
    <item>
      <title>Re: More efficient way to search for strings in a character field?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76911#M16617</link>
      <description>The INDEX function appears to be the most efficient, as compared to the recently added FIND function.  &lt;BR /&gt;
&lt;BR /&gt;
Also, using your coding example, I also tested using OR condition rather than IF THEN ELSE  logic and again INDEX was more efficient, say with a 1 million DO loop iteration with an OUTPUT.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 12 Mar 2009 14:34:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76911#M16617</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-12T14:34:49Z</dc:date>
    </item>
    <item>
      <title>Re: More efficient way to search for strings in a character field?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76912#M16618</link>
      <description>Maybe indexc is more efficient in this context.&lt;BR /&gt;
&lt;BR /&gt;
if indexc(abc,'STRING1',...,'STRING6') &amp;gt; 0 then NEW_FIELD = 'RESULT1';</description>
      <pubDate>Thu, 12 Mar 2009 17:52:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76912#M16618</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-03-12T17:52:34Z</dc:date>
    </item>
    <item>
      <title>Re: More efficient way to search for strings in a character field?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76913#M16619</link>
      <description>The function INDEXC applies to a character (one or more specified as argument #2) search within a string (argument #1), not a string of characters to search for.&lt;BR /&gt;
&lt;BR /&gt;
Scott Barry&lt;BR /&gt;
SBBWorks, Inc.</description>
      <pubDate>Thu, 12 Mar 2009 20:14:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/More-efficient-way-to-search-for-strings-in-a-character-field/m-p/76913#M16619</guid>
      <dc:creator>sbb</dc:creator>
      <dc:date>2009-03-12T20:14:56Z</dc:date>
    </item>
  </channel>
</rss>

