<?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: SUBSTRN in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765185#M242358</link>
    <description>&lt;P&gt;Explanation:&lt;/P&gt;
&lt;P&gt;If you start in column -1 and want 3 characters then the string you want ends at column 1.&lt;/P&gt;
&lt;P&gt;If you start in column&amp;nbsp; S and want L characters then the string ends at column (S+L-1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 31 Aug 2021 21:39:55 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2021-08-31T21:39:55Z</dc:date>
    <item>
      <title>SUBSTRN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765166#M242351</link>
      <description>&lt;P&gt;I have&amp;nbsp;&lt;/P&gt;&lt;P&gt;x=abcdefg&lt;/P&gt;&lt;P&gt;y= SUBSTRN(x,-1,3);&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;It returns me abc. but I want efg.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 20:09:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765166#M242351</guid>
      <dc:creator>GingerJJ</dc:creator>
      <dc:date>2021-08-31T20:09:20Z</dc:date>
    </item>
    <item>
      <title>Re: SUBSTRN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765169#M242353</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393829"&gt;@GingerJJ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x=abcdefg&lt;/P&gt;
&lt;P&gt;y= SUBSTRN(x,-1,3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It returns me abc. but I want efg.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The real question is do you want the last three characters, regardless of length, or do you want the substring that starts in the 5th position to the end of the value, or some other rule?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The above returns 'abc' because you told it to start in a position before the string and get the following 3 characters.&lt;/P&gt;
&lt;P&gt;From the documentation : If the position that you specify is non-positive, the result is truncated at the beginning, so that the first character of the result is the first character of the string. &lt;/P&gt;
&lt;P&gt;Position is the second parameter, or where to start&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Assuming you want the last 3 characters try &lt;/P&gt;
&lt;PRE&gt;y= SUBSTRN(x,length(x)-2);&lt;/PRE&gt;
&lt;P&gt;Why minus 2 you may ask. The function want a starting position in the second position. If the length of string is 7, then you want positions 5, 6 and 7 (assuming you want three characters). So to get 5 you want 7-2.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 20:37:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765169#M242353</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2021-08-31T20:37:15Z</dc:date>
    </item>
    <item>
      <title>Re: SUBSTRN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765175#M242357</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/393829"&gt;@GingerJJ&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;I have&amp;nbsp;&lt;/P&gt;
&lt;P&gt;x=abcdefg&lt;/P&gt;
&lt;P&gt;y= SUBSTRN(x,-1,3);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It returns me abc. but I want efg.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;-1,3 does not return abc&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;53         data _null_;
54            x='abcdefg';
55            do i = -1 to 8;
56               y=SUBSTRN(x,i,3);
57               put i 2. +1 y=$hex10. +1 y=;
58               end;
59            run;

-1 y=6120202020  y=a
 0 y=6162202020  y=ab
 1 y=6162632020  y=abc
 2 y=6263642020  y=bcd
 3 y=6364652020  y=cde
 4 y=6465662020  y=def
 5 y=6566672020  y=efg
 6 y=6667202020  y=fg
 7 y=6720202020  y=g
 8 y=2020202020  y= &lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 21:15:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765175#M242357</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2021-08-31T21:15:08Z</dc:date>
    </item>
    <item>
      <title>Re: SUBSTRN</title>
      <link>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765185#M242358</link>
      <description>&lt;P&gt;Explanation:&lt;/P&gt;
&lt;P&gt;If you start in column -1 and want 3 characters then the string you want ends at column 1.&lt;/P&gt;
&lt;P&gt;If you start in column&amp;nbsp; S and want L characters then the string ends at column (S+L-1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 31 Aug 2021 21:39:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/SUBSTRN/m-p/765185#M242358</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2021-08-31T21:39:55Z</dc:date>
    </item>
  </channel>
</rss>

