<?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 a character in a string from reverse in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/405183#M98538</link>
    <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;'s/[\d_]+$//'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This means replace more than one digit or underline characters&amp;nbsp; [\d_]+ (at the end of string) with null .&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 18 Oct 2017 12:37:57 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2017-10-18T12:37:57Z</dc:date>
    <item>
      <title>Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404573#M98341</link>
      <description>&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a raw file whose name is&amp;nbsp;Client_Product_Ash_HCP_Address_20171006030056_2803.txt. I read the file into the SAS but only want the part of the file name just before the second "_" from the reverse. So, basically the output file name should look like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Client_Product_Ash_HCP_Address&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Another example would be Client_Product_Ash_HCP_Contact_20171006030058_2870.txt. The output file name should look like this:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Client_Product_Ash_HCP_Contact&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Any ideas on how to use a combination of Substr and index function to achieve this goal?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Chandan Mishra&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 16 Oct 2017 19:56:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404573#M98341</guid>
      <dc:creator>chandan_mishra</dc:creator>
      <dc:date>2017-10-16T19:56:02Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404576#M98342</link>
      <description>&lt;P&gt;Use ANYDIGIT to find the location of the first digit.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Use SUBSTR to then extract the part desired.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;index = anydigit(string);&lt;/P&gt;
&lt;P&gt;string_want = substr(string, 1, index-2); *not sure how much you'll need to minus to get what you want, but you can test it and see;&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>Mon, 16 Oct 2017 20:02:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404576#M98342</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-16T20:02:14Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404584#M98344</link>
      <description>&lt;P&gt;You can use CALL SCAN to find the position of the second underscore delimited word and use P to sub-string everything from column 1 to the desired column.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;27         data _null_;
28            file = 'Client_Product_Ash_HCP_Contact_20171006030058_2870.txt';
29            call scan(file,-2,p,l,'_');
30            part = substrn(file,1,p-2);
31            put _all_;
32            run;

file=Client_Product_Ash_HCP_Contact_20171006030058_2870.txt p=32 l=14 part=Client_Product_Ash_HCP_Contact _ERROR_=0 _N_=1&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Oct 2017 20:10:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404584#M98344</guid>
      <dc:creator>data_null__</dc:creator>
      <dc:date>2017-10-16T20:10:23Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404588#M98345</link>
      <description>&lt;P&gt;You could use SCAN function to concatenate the 2nd-last and&amp;nbsp;last&amp;nbsp;"words" (where '_' is the word delimiter).&amp;nbsp; Then use TRANWRD to convert it to blank.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  txt="Client_Product_Ash_HCP_Address_20171006030056_2803.txt";
  drop_text='_'||catx('_',scan(txt,-2,'_'),scan(txt,-1,'_'));
  want=tranwrd(txt,trim(drop_text),' ');
  put (_all_) (= /);
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 16 Oct 2017 20:16:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404588#M98345</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2017-10-16T20:16:50Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404760#M98379</link>
      <description>&lt;P&gt;Since&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15410"&gt;@data_null__&lt;/a&gt;&amp;nbsp;John King has already posted a wonderful solution.&lt;/P&gt;
&lt;P&gt;I would like to post another solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; data _null_;
            file = 'Client_Product_Ash_HCP_Contact_20171006030058_2870.txt';
            part = prxchange('s/[\d_]+$//',1,scan(file,1,'.'));
            put _all_;
          run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 17 Oct 2017 12:19:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404760#M98379</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-17T12:19:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404954#M98461</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to search for how prxchange&amp;nbsp;works but it seems really complicated. The syntax is:&lt;/P&gt;&lt;P&gt;prxchange( regular expression|id, occurrence, source )&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I understood the occurence&amp;nbsp;and source part but how to define the regular expression|id part.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;P&gt;Chandan Mishra&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 19:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404954#M98461</guid>
      <dc:creator>chandan_mishra</dc:creator>
      <dc:date>2017-10-17T19:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404956#M98463</link>
      <description>&lt;P&gt;Regular expressions are actually from PERL, they don't originate with SAS, but they're highly useful so many languages now implement this.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Perl documentation and builder are here:&lt;/P&gt;
&lt;P&gt;&lt;A href="https://perldoc.perl.org/perlre.html" target="_blank"&gt;https://perldoc.perl.org/perlre.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://regex101.com/" target="_blank"&gt;https://regex101.com/&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Oct 2017 19:23:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/404956#M98463</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-10-17T19:23:55Z</dc:date>
    </item>
    <item>
      <title>Re: Find a character in a string from reverse</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/405183#M98538</link>
      <description>&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token string"&gt;'s/[\d_]+$//'&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This means replace more than one digit or underline characters&amp;nbsp; [\d_]+ (at the end of string) with null .&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 18 Oct 2017 12:37:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-a-character-in-a-string-from-reverse/m-p/405183#M98538</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-10-18T12:37:57Z</dc:date>
    </item>
  </channel>
</rss>

