<?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: index function in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807102#M318128</link>
    <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I thought index function finds the position of first character of second string in the first string. As soon as it find it, it returns the position&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;H1 id="n0vxokxhv8lr84n10nrbnzp7gnba" class="xisDoc-title"&gt;INDEX Function&lt;/H1&gt;
&lt;P class="xisDoc-shortDescription"&gt;Searches a character expression for a &lt;STRONG&gt;string of characters&lt;/STRONG&gt;, and returns the position of the string's first character for the first occurrence of the string.&lt;/P&gt;
&lt;P class="xisDoc-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-shortDescription"&gt;If you read the description of the INDEX function as copied from the documentation then it should be clear how it works - it is trying to find the &lt;STRONG&gt;whole of the second string&lt;/STRONG&gt; in the first one.&lt;/P&gt;</description>
    <pubDate>Mon, 11 Apr 2022 07:00:25 GMT</pubDate>
    <dc:creator>SASKiwi</dc:creator>
    <dc:date>2022-04-11T07:00:25Z</dc:date>
    <item>
      <title>index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804911#M317007</link>
      <description>&lt;P&gt;Hello team&lt;/P&gt;
&lt;P&gt;why q is equal to 0.&lt;/P&gt;
&lt;P&gt;b = 'x=y'&amp;nbsp; &amp;nbsp; &amp;nbsp; trim(b) will be same, b doesn't have spaces that trim b takes that out!!&lt;/P&gt;
&lt;PRE&gt;data _null_;
length a b $14;
a='ABC.DEF (X=Y) ';
b='X=Y';
q=index(a, b);
w=index(a, trim(b));
put q= w=;
run;
q=0 and w=10 /*log shows it*/&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;thanks for the response. b&amp;amp;b&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Mar 2022 22:55:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804911#M317007</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-03-29T22:55:31Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804919#M317012</link>
      <description>&lt;P&gt;SAS uses FIXED LENGTH character variables.&lt;/P&gt;
&lt;P&gt;You defined B to hold 14 bytes.&amp;nbsp; You assigned a value that was only 3 bytes long, so the other 11 bytes were filled with spaces.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 00:09:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804919#M317012</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-03-30T00:09:51Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804959#M317045</link>
      <description>&lt;P&gt;&lt;EM&gt;&amp;gt; b doesn't have spaces that trim b takes that out&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Yes it does. Remove the LENGTH statement and it won't.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:23:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804959#M317045</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2022-03-30T06:23:49Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804966#M317050</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/202329"&gt;@GN0001&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;trim(b) will be same, b doesn't have spaces&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;b DOES have spaces, because you defined it with a length of 14, so the remaining bytes have to be padded with blanks.&lt;/P&gt;
&lt;P&gt;If you do not include b in the LENGTH statement, then the data step compiler will use the length of the assigned literal string to define the length of the variable.&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 06:44:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/804966#M317050</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-03-30T06:44:08Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/805082#M317090</link>
      <description>&lt;P&gt;Here is code that will demonstrate, in one way, the actual value of B for the first call to index.&lt;/P&gt;
&lt;PRE&gt;data _null_;
length a b $14;
a='ABC.DEF (X=Y) ';
b='X=Y';
z= quote(b);
put z=;
run;&lt;/PRE&gt;
&lt;P&gt;Read the LOG and you will see that the variable Z has a bunch of blanks before the final quote. Which means those blanks are there unless removed.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Mar 2022 14:56:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/805082#M317090</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2022-03-30T14:56:42Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807084#M318116</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;
&lt;P&gt;I thought index function finds the position of first character of second string in the first string. As soon as it find it, it returns the position. I didn't know that it checks all the second string in the first string, then it returns the first character position.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;
&lt;P&gt;blue &amp;amp; blue&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 02:38:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807084#M318116</guid>
      <dc:creator>GN0001</dc:creator>
      <dc:date>2022-04-11T02:38:53Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807102#M318128</link>
      <description>&lt;BLOCKQUOTE&gt;
&lt;P&gt;I thought index function finds the position of first character of second string in the first string. As soon as it find it, it returns the position&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;H1 id="n0vxokxhv8lr84n10nrbnzp7gnba" class="xisDoc-title"&gt;INDEX Function&lt;/H1&gt;
&lt;P class="xisDoc-shortDescription"&gt;Searches a character expression for a &lt;STRONG&gt;string of characters&lt;/STRONG&gt;, and returns the position of the string's first character for the first occurrence of the string.&lt;/P&gt;
&lt;P class="xisDoc-shortDescription"&gt;&amp;nbsp;&lt;/P&gt;
&lt;P class="xisDoc-shortDescription"&gt;If you read the description of the INDEX function as copied from the documentation then it should be clear how it works - it is trying to find the &lt;STRONG&gt;whole of the second string&lt;/STRONG&gt; in the first one.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 07:00:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807102#M318128</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2022-04-11T07:00:25Z</dc:date>
    </item>
    <item>
      <title>Re: index function</title>
      <link>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807107#M318129</link>
      <description>&lt;P&gt;See Maxim 46 and always keep its consequences in mind.&lt;/P&gt;</description>
      <pubDate>Mon, 11 Apr 2022 07:56:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/index-function/m-p/807107#M318129</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2022-04-11T07:56:36Z</dc:date>
    </item>
  </channel>
</rss>

