<?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: Find position of the last character in a string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415491#M101905</link>
    <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  string='123-56-8-101212';
  pos=findc(string,'-','b');
  put pos=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Wed, 22 Nov 2017 12:43:43 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-11-22T12:43:43Z</dc:date>
    <item>
      <title>Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415337#M101837</link>
      <description>&lt;P&gt;Hi Everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to find the position of the last "-" in the string below&lt;/P&gt;
&lt;P&gt;123-56-8-101212&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;so that last "-" is in position&amp;nbsp;9.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Can anyone please help?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;KEY IS: reverse vs regular.&lt;/P&gt;
&lt;P&gt;pos=index(reverse(lcat),'-'); give the position of the last '-' using the length of the whole VARIABLE (specified in datastep, format...)&lt;/P&gt;
&lt;P&gt;pos1=findc(Lcat,'-','b');&lt;SPAN&gt;give the position of the last '-' using the length of the whole&amp;nbsp;STRING&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
DATA test;
  INFILE DATALINES DELIMITER=',' DSD;
  INPUT status &amp;amp; $100.;
  DATALINES;
"No aproved by Tong"
"No Approval by Paul"
"No Approval by Ryan"
"No approval by Amy"
;
RUN;


data test1; set test;
length=length(Status);
findc=findw(status,'by');
supervisor=substr(status,findc+2);run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 20 Dec 2017 21:50:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415337#M101837</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-12-20T21:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415338#M101838</link>
      <description>&lt;P&gt;Here's one approach:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;data _null_;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; string='123-56-8-101212';&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; pos=length(string)-index(reverse(string),'-')+1;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;&amp;nbsp; put pos=;&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT face="courier new,courier"&gt;run;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 21 Nov 2017 23:31:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415338#M101838</guid>
      <dc:creator>AllanBowe</dc:creator>
      <dc:date>2017-11-21T23:31:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415346#M101840</link>
      <description>&lt;P&gt;I think this example work only when there the length of string is fix.&lt;/P&gt;
&lt;P&gt;In a datafile, the Length(project) change while the index(reverse(project),'-') count from the end of the whole variable itself, so it is not working.&lt;/P&gt;
&lt;P&gt;I need to change to&lt;/P&gt;
&lt;P&gt;pos=&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;100&lt;/STRONG&gt;&lt;/FONT&gt;-index(reverse(project),'-')+1; 100 is the length of the variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wonder if there is any better way.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;HC&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA test;
  INFILE DATALINES DELIMITER=',' DSD;
  INPUT project &amp;amp; &lt;STRONG&gt;&lt;FONT color="#FF0000"&gt;$100.&lt;/FONT&gt;&lt;/STRONG&gt;;
  DATALINES;
"General DYn - CKXy:GD-CQASUB56209-2A10-520"
"General Dyn - Technology:XP-CQA6521-5A10-520"
;
RUN;

data test;
set test;
length=length(project);
last=index(reverse(project),'-');
pos=length(project)-index(reverse(project),'-')+1;
  var=(substr(project,pos,5));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 00:29:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415346#M101840</guid>
      <dc:creator>hhchenfx</dc:creator>
      <dc:date>2017-11-22T00:29:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415347#M101841</link>
      <description>&lt;P&gt;Trim it after reversing it. Otherwise you add leading blanks.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;SCAN() allows you to use negative indexes, ie searching backwards which would be a much simpler approach and a single function.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 00:36:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415347#M101841</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T00:36:58Z</dc:date>
    </item>
    <item>
      <title>Re: Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415348#M101842</link>
      <description>If you’re not already aware, DLM in the INFILE statement also allows for multiple delimiters if you want to read it into separate variables directly.</description>
      <pubDate>Wed, 22 Nov 2017 00:38:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415348#M101842</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-11-22T00:38:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415359#M101845</link>
      <description>&lt;P&gt;Cramming it all into one statement ....&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;set have;&lt;/P&gt;
&lt;P&gt;last_dash = length(string) - length(scan(string, -1, '-') );&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Nov 2017 02:15:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415359#M101845</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-11-22T02:15:35Z</dc:date>
    </item>
    <item>
      <title>Re: Find position of the last character in a string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415491#M101905</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  string='123-56-8-101212';
  pos=findc(string,'-','b');
  put pos=;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 22 Nov 2017 12:43:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-position-of-the-last-character-in-a-string/m-p/415491#M101905</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-11-22T12:43:43Z</dc:date>
    </item>
  </channel>
</rss>

