<?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: check if string contain substring. in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981138#M379039</link>
    <description>Yeah. Agree.&lt;BR /&gt;It is all depend on what OP want. This example maybe is just an example, only OP know the real demand and real data .</description>
    <pubDate>Sat, 20 Dec 2025 08:36:48 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2025-12-20T08:36:48Z</dc:date>
    <item>
      <title>check if string contain substring.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981096#M379029</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;
&lt;P&gt;I want to check if string contain substring.&lt;/P&gt;
&lt;P&gt;I do it with Find function.&lt;/P&gt;
&lt;P&gt;What is the reason that&amp;nbsp; &amp;nbsp;example 1 is working 100% but example 2 is not working well?&lt;/P&gt;
&lt;P&gt;30000 exist in&amp;nbsp;40000,80000,30000&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example1_find;
string = "40000,80000,30000";
substring=30000;
char_substring=compress(put(substring,best.));
pos1 = find(string,char_substring); 
IF POS1&amp;gt;0 then ind=1;else ind=0;
run;


data example2_find;
string = "I Love- Banana";
substring='Banana';
pos1 = find(string,substring); 
IF POS1&amp;gt;0 then ind=1;else ind=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 19 Dec 2025 14:47:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981096#M379029</guid>
      <dc:creator>Ronein</dc:creator>
      <dc:date>2025-12-19T14:47:50Z</dc:date>
    </item>
    <item>
      <title>Re: check if string contain substring.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981114#M379030</link>
      <description>&lt;P&gt;Read the documentation on the FIND() function, in particular look at the various modifiers that it offers.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Your first example does not work because of the lengths of your character variables.&amp;nbsp; Since you did not tell SAS explicitly what length to use for them it followed its internal rules for guessing what length to use.&amp;nbsp; So STRING is defined as $17 since the first value you assigned to it was 17 bytes long. And CHAR_SUBSTRING was defined as $12 since the default width for the BEST format is 12.&amp;nbsp; So that means FIND() was unable to located a 3 followed by 4 zeros and 7 spaces in "40000,80000,30000".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are some things you could try:&lt;/P&gt;
&lt;UL&gt;
&lt;LI&gt;Use the TRIM(), STRIP() or even CATS() function to removing leading/trailing spaces.&lt;/LI&gt;
&lt;LI&gt;Use the T modifier in the FIND() function call.&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Note: Since you seem to be searching for words you might want to use the FINDW() function instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2025 17:23:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981114#M379030</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2025-12-19T17:23:09Z</dc:date>
    </item>
    <item>
      <title>Re: check if string contain substring.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981116#M379032</link>
      <description>&lt;P&gt;How about this? It works! If you want to compare string to another character string, don't make the variable numeric and then convert it to a character string. As&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp; points out, this can be a problem. Make the variable character to begin with.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data example1_find;
string = "40000,80000,30000";
substring='30000';
ind = find(string,substring)&amp;gt;0; 
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;... but wait, that fails to give the correct answer when &lt;FONT face="courier new,courier"&gt;string = "40000,80000,330000"&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So, using FINDW as suggested by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159"&gt;@Tom&lt;/a&gt;&amp;nbsp;is definitely the way to go.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Dec 2025 18:51:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981116#M379032</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-12-19T18:51:35Z</dc:date>
    </item>
    <item>
      <title>Re: check if string contain substring.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981134#M379035</link>
      <description>As Tom pointed out ,using strip to get rid of trailing blanks:&lt;BR /&gt;pos1 = find(string,  strip( char_substring ));&lt;BR /&gt;&lt;BR /&gt;Otherwise ,sas would take 3000 as 3000blankblank.....  Not 3000</description>
      <pubDate>Sat, 20 Dec 2025 07:27:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981134#M379035</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-12-20T07:27:48Z</dc:date>
    </item>
    <item>
      <title>Re: check if string contain substring.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981137#M379038</link>
      <description>&lt;P&gt;In my opinion, any solution involving the FIND function will fail for the reasons I gave above. You really want the FINDW function.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But to go a step beyond the actual code, best practices are to treat numbers as numeric variables, and not as a character string that you have to pull apart somehow. So even if&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/159549"&gt;@Ronein&lt;/a&gt;&amp;nbsp;received the data as a character string, they should be converted to numbers for any future use, including logical testing like comparing to the number 30000. If these are numbers and not character strings, then these questions about how to find 30000 never arise.&lt;/P&gt;</description>
      <pubDate>Sat, 20 Dec 2025 08:33:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981137#M379038</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2025-12-20T08:33:26Z</dc:date>
    </item>
    <item>
      <title>Re: check if string contain substring.</title>
      <link>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981138#M379039</link>
      <description>Yeah. Agree.&lt;BR /&gt;It is all depend on what OP want. This example maybe is just an example, only OP know the real demand and real data .</description>
      <pubDate>Sat, 20 Dec 2025 08:36:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/check-if-string-contain-substring/m-p/981138#M379039</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2025-12-20T08:36:48Z</dc:date>
    </item>
  </channel>
</rss>

