<?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: Flagging when a String is within another String in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566725#M159330</link>
    <description>It can be as simple as:&lt;BR /&gt;&lt;BR /&gt;FLAG = find(b, a, 'it') GE 1;</description>
    <pubDate>Mon, 17 Jun 2019 20:53:05 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-06-17T20:53:05Z</dc:date>
    <item>
      <title>Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566717#M159322</link>
      <description>&lt;P&gt;I want to take a dataset like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input a $ b $;
	datalines;
123abc one
123abc two
123abc 123abc45
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And flag when variable 'a' is fully contained within variable 'b',&lt;/P&gt;&lt;P&gt;such that I return this table:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	input a $ b $ flag;
	datalines;
123abc one 0
123abc two 0
123abc 123abc45 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 20:19:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566717#M159322</guid>
      <dc:creator>publicSynechism</dc:creator>
      <dc:date>2019-06-17T20:19:58Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566720#M159325</link>
      <description>&lt;P&gt;Have you tried the FIND() or INDEX() functions?&lt;/P&gt;
&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/216525"&gt;@publicSynechism&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I want to take a dataset like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input a $ b $;
	datalines;
123abc one
123abc two
123abc 123abc45
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;And flag when variable 'a' is fully contained within variable 'b',&lt;/P&gt;
&lt;P&gt;such that I return this table:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
	input a $ b $ flag;
	datalines;
123abc one 0
123abc two 0
123abc 123abc45 1
;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 20:35:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566720#M159325</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-17T20:35:11Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566723#M159328</link>
      <description>&lt;P&gt;I believe this will accomplish the results you are looking for:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA WORK.WANT;
	SET WORK.HAVE;
		 IF FIND(TRIM(b),TRIM(a),'i') GE 1 THEN DO; FLAG=1;	END;
	ELSE IF FIND(TRIM(b),TRIM(a),'i') LT 1 THEN DO; FLAG=0; END;
RUN;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 20:48:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566723#M159328</guid>
      <dc:creator>tsap</dc:creator>
      <dc:date>2019-06-17T20:48:44Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566725#M159330</link>
      <description>It can be as simple as:&lt;BR /&gt;&lt;BR /&gt;FLAG = find(b, a, 'it') GE 1;</description>
      <pubDate>Mon, 17 Jun 2019 20:53:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566725#M159330</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-17T20:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566726#M159331</link>
      <description>&lt;P&gt;Yes, but I believe it's returning 0 whether it finds the string or not, since it will return the start position of the found string. It will always be the case in my data that startpos = 0.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
	set have;
	out=find(a,b,'t');
	out2=index(trim(a),b);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Jun 2019 20:53:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566726#M159331</guid>
      <dc:creator>publicSynechism</dc:creator>
      <dc:date>2019-06-17T20:53:47Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566728#M159333</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/216525"&gt;@publicSynechism&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;Yes, but I believe it's returning 0 whether it finds the string or not, since it will return the start position of the found string. It will always be the case in my data that startpos = 0.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have2;
	set have;
	out=find(a,b,'t');
	out2=index(trim(a),b);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Which is why the check is for Greater than or equal to 1.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;From the documentation:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The FIND function searches &lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;string&lt;/SPAN&gt;&lt;SPAN&gt; for the first occurrence of the specified &lt;/SPAN&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;substring&lt;/SPAN&gt;&lt;SPAN&gt;, and &lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;returns the position of that substring&lt;/STRONG&gt;&lt;/FONT&gt;. &lt;STRONG&gt;&lt;FONT color="#FF9900"&gt;If the substring is not found in &lt;/FONT&gt;&lt;/STRONG&gt;&lt;/SPAN&gt;&lt;STRONG&gt;&lt;FONT color="#FF9900"&gt;&lt;SPAN class="xis-userSuppliedValue"&gt;string&lt;/SPAN&gt;, FIND returns a value of 0.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000000"&gt;Setting the flag as follows will always return a 0 or 1.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;FLAG = find(b, a, 'it') &amp;gt;= 1;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 17 Jun 2019 21:03:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566728#M159333</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-06-17T21:03:53Z</dc:date>
    </item>
    <item>
      <title>Re: Flagging when a String is within another String</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566858#M159379</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
	input a $ b $;
	flag=ifn(find(b,a,'it'),1,0);
	datalines;
123abc one
123abc two
123abc 123abc45
;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 18 Jun 2019 13:21:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Flagging-when-a-String-is-within-another-String/m-p/566858#M159379</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2019-06-18T13:21:24Z</dc:date>
    </item>
  </channel>
</rss>

