<?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: Problem with finding a substring in a string when it exists in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169328#M32480</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello i am new user &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Oct 2014 13:55:53 GMT</pubDate>
    <dc:creator>gqy</dc:creator>
    <dc:date>2014-10-12T13:55:53Z</dc:date>
    <item>
      <title>Problem with finding a substring in a string when it exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169324#M32476</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Sample data attached (Sheet1).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I want to produce a column called all_nonmatch which would give me the issue numbers in column B but not column C (eg, for polnum = A, the result would be '2').&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'm open to other solutions. The one I'm using is sufficient I believe, because if I hardcode the numbers in (as character substrings), it works. However, the goal is to create a loop that would go through each issue (there could be up to 6 issues) and check for it vs the matched_issues list.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Here's my code (I was testing, I haven't converted to a loop/macros/whatever I'll need to production-ize it). I've tried a lot of different things (using macro variables instead of a new column for issue being one example). If I force the length of the 'issue' variable to 1 it works (for the one character numbers-- but these will go up to 3 characters), and if I hardcode the string '1' instead of issue as the 'excerpt' argument for INDEXW it works. This leads me to believe that I have some kind of trailing blank issue. But I also wrapped the SCAN function with every kind of stripping function that i know (STRIP, COMPRESS, COMPBL, TRIM, LEFT) to no avail. I tried converting the issue variable to a number.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;My output is on the output tab. Everything ends up in the nonmatch columns, even though there should be matches.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test2; set test1;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; issue=scan(all_issues,1,';');&lt;/P&gt;&lt;P&gt;&amp;nbsp; if indexw(matched_issues,issue,';')&amp;gt;0 then match1=issue;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else nonmatch1=issue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; issue=scan(all_issues,2,';');&lt;/P&gt;&lt;P&gt;&amp;nbsp; if indexw(matched_issues,issue,';')&amp;gt;0 then match2=issue;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else nonmatch2=issue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; issue=scan(all_issues,3,';');&lt;/P&gt;&lt;P&gt;&amp;nbsp; if indexw(matched_issues,issue,';')&amp;gt;0 then match3=issue;&lt;/P&gt;&lt;P&gt;&amp;nbsp; else nonmatch3=issue;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; all_nonmatch=catx(';',nonmatch1,nonmatch2,nonmatch3);er&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;++&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 14:44:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169324#M32476</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2014-10-02T14:44:32Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with finding a substring in a string when it exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169325#M32477</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try changing to &lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt; indexw(matched_issues,strip(issue),&lt;/SPAN&gt;&lt;SPAN style="color: #800080; font-size: 10pt; font-family: SAS Monospace;"&gt;';'&lt;/SPAN&gt;&lt;SPAN style="font-size: 10pt; font-family: SAS Monospace;"&gt;)&amp;gt;&lt;/SPAN&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: SAS Monospace;"&gt;0&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="color: #008080; font-size: 10pt; font-family: SAS Monospace;"&gt;If you look at the size of ISSUE in the result data set, you'll likely find it is 200 characters and is using the blanks at the end for the comparison.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 15:12:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169325#M32477</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-02T15:12:00Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with finding a substring in a string when it exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169326#M32478</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;That works. Thanks.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But why does it only work that way? Why doesn't this work:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;issue=strip(scan(XXX));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 15:17:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169326#M32478</guid>
      <dc:creator>cau83</dc:creator>
      <dc:date>2014-10-02T15:17:10Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with finding a substring in a string when it exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169327#M32479</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I suspect it is because Indexw is searching for what you have specified as a "word". It is up to you to make sure that "word" is the content you actually want.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Oct 2014 18:02:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169327#M32479</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2014-10-02T18:02:27Z</dc:date>
    </item>
    <item>
      <title>Re: Problem with finding a substring in a string when it exists</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169328#M32480</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;hello i am new user &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Oct 2014 13:55:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Problem-with-finding-a-substring-in-a-string-when-it-exists/m-p/169328#M32480</guid>
      <dc:creator>gqy</dc:creator>
      <dc:date>2014-10-12T13:55:53Z</dc:date>
    </item>
  </channel>
</rss>

