<?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 One string variable contains another string variable? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427463#M105426</link>
    <description>Hi SAS experts!&lt;BR /&gt;I am wondering if there are some SAS functions that can tell me if one string variable contains another string variable? The "index" function can tell us whether one string variable contains a fixed string, but what if the string I am searching for is varying among different observations?&lt;BR /&gt;&lt;BR /&gt;For example: there are two variables: v1 and v2. V1 is a short string and v2 is a long string. V1 can be "sgd" and "kjh" And v2 can be "hdsgdk" and "ukjhso". Obviously v2 contains v1 for these two cases. Any SAS functions can help me with this? Thanks!</description>
    <pubDate>Sat, 13 Jan 2018 20:03:16 GMT</pubDate>
    <dc:creator>Shortselling123</dc:creator>
    <dc:date>2018-01-13T20:03:16Z</dc:date>
    <item>
      <title>One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427463#M105426</link>
      <description>Hi SAS experts!&lt;BR /&gt;I am wondering if there are some SAS functions that can tell me if one string variable contains another string variable? The "index" function can tell us whether one string variable contains a fixed string, but what if the string I am searching for is varying among different observations?&lt;BR /&gt;&lt;BR /&gt;For example: there are two variables: v1 and v2. V1 is a short string and v2 is a long string. V1 can be "sgd" and "kjh" And v2 can be "hdsgdk" and "ukjhso". Obviously v2 contains v1 for these two cases. Any SAS functions can help me with this? Thanks!</description>
      <pubDate>Sat, 13 Jan 2018 20:03:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427463#M105426</guid>
      <dc:creator>Shortselling123</dc:creator>
      <dc:date>2018-01-13T20:03:16Z</dc:date>
    </item>
    <item>
      <title>Re: One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427464#M105427</link>
      <description>&lt;P&gt;I did a small test though i am not sure what you are after:&lt;/P&gt;&lt;P&gt;Using index, indexw, find and findw&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
V1="sgd";
v2="hdsgdk";
output;
V1="kjh";
v2="ukjhso";
output;
run;

data want;
set have;
index=index(v2,v1);
indexw=indexw(v2,v1);
find=find(v2,v1);
findw=findw(v2,v1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Jan 2018 20:13:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427464#M105427</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-01-13T20:13:44Z</dc:date>
    </item>
    <item>
      <title>Re: One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427465#M105428</link>
      <description>&lt;P&gt;Unless I'm not understanding the question properly you've answered it yourself&amp;nbsp;&lt;img id="smileyhappy" class="emoticon emoticon-smileyhappy" src="https://communities.sas.com/i/smilies/16x16_smiley-happy.png" alt="Smiley Happy" title="Smiley Happy" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;

	v1="sgd";
	v2="hdsgdk";

	if index(v2,v1) then put "found";
	else put "not found";

	v1="kjh";
	v2="ukjhso";

	if index(v2,v1) then put "found";
	else put "not found";

	/* Just for contrast */

	v1="sgd";
	v2="ukjhso";

	if index(v2,v1) then put "found";
	else put "not found";

run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 13 Jan 2018 20:16:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427465#M105428</guid>
      <dc:creator>ChrisBrooks</dc:creator>
      <dc:date>2018-01-13T20:16:26Z</dc:date>
    </item>
    <item>
      <title>Re: One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427483#M105442</link>
      <description>&lt;P&gt;As others have shown, the second parameter in INDEX can refer to a variable.&amp;nbsp; It doesn't have to be a fixed string.&amp;nbsp; However, when you use a variable, there is one issue that you might need to attend to:&amp;nbsp; the possibility of trailing blanks.&amp;nbsp; If you want the variable V1 to be the second parameter (the string to be searched for), it would be safer to use strip(v1) as the second parameter.&lt;/P&gt;</description>
      <pubDate>Sat, 13 Jan 2018 22:43:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427483#M105442</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2018-01-13T22:43:33Z</dc:date>
    </item>
    <item>
      <title>Re: One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427525#M105460</link>
      <description>Right. Thanks! Not sure why Index did not work last time...</description>
      <pubDate>Sun, 14 Jan 2018 17:39:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427525#M105460</guid>
      <dc:creator>Shortselling123</dc:creator>
      <dc:date>2018-01-14T17:39:43Z</dc:date>
    </item>
    <item>
      <title>Re: One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427526#M105461</link>
      <description>Thanks! This is really helpful.</description>
      <pubDate>Sun, 14 Jan 2018 17:40:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427526#M105461</guid>
      <dc:creator>Shortselling123</dc:creator>
      <dc:date>2018-01-14T17:40:02Z</dc:date>
    </item>
    <item>
      <title>Re: One string variable contains another string variable?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427527#M105462</link>
      <description>Thanks! This is helpful!</description>
      <pubDate>Sun, 14 Jan 2018 17:40:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/One-string-variable-contains-another-string-variable/m-p/427527#M105462</guid>
      <dc:creator>Shortselling123</dc:creator>
      <dc:date>2018-01-14T17:40:19Z</dc:date>
    </item>
  </channel>
</rss>

