<?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: Selecting character strings whose last 3 characters ends with certain characters in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840864#M332474</link>
    <description>&lt;P&gt;A macro solution could be obtained by marrying the wonderful %sysfunc() and prx*() functions. This works for me:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=20040;
%let regex=/012$|040$/;
%let regid=%sysfunc(prxparse(&amp;amp;regex));
%put &amp;amp;=regid;
%let valid = %sysfunc(prxmatch(&amp;amp;regid, &amp;amp;string));
%put &amp;amp;=valid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code could be further condensed but this is the most descriptive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=20040;
%let valid = %sysfunc(prxmatch(/012$|040$/, &amp;amp;string));
%put &amp;amp;=valid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro variable "valid" has a value of 0 (zero) if there is no match or a positive integer indicating startposition of the pattern searched for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Needless to say I am a fan of the prx functions and highly recommend them in these situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
    <pubDate>Wed, 26 Oct 2022 13:06:18 GMT</pubDate>
    <dc:creator>jklaverstijn</dc:creator>
    <dc:date>2022-10-26T13:06:18Z</dc:date>
    <item>
      <title>Selecting character strings whose last 3 characters ends with certain characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840662#M332395</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have character strings which look like: 20012, 24012, 20021, 28021, 20040, etc.&lt;/P&gt;&lt;P&gt;I want to select character strings whose last 3 characters are 012 or 040, for example, using %let statement (e.g., %let valid = )&lt;/P&gt;&lt;P&gt;That is, 20012, 24012, and 20040 should be selected in this example.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Can anybody help me completing the let macro statement?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yoko&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 19:34:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840662#M332395</guid>
      <dc:creator>Yoko</dc:creator>
      <dc:date>2022-10-25T19:34:25Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting character strings whose last 3 characters ends with certain characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840664#M332397</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $;
cards;
20012
24012
20021
28021
20040
;
data want;
    set have;
    if left(reverse(string)) in :('210','040') then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;No macros needed. Please note that the IF statement requires a colon before ('210','040') which then tests if the reverse of the string&amp;nbsp;&lt;EM&gt;starts with&lt;/EM&gt; these values, and if it starts with these values, then the un-reversed string ends with the reverse of these values. Please note that I am testing against&amp;nbsp;('210','040') which is the reverse of what you asked for (you asked for: ends with 012 or 040), but it works in this application because I am testing the reverse strings.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 20:58:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840664#M332397</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-10-25T20:58:42Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting character strings whose last 3 characters ends with certain characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840678#M332404</link>
      <description>&lt;P&gt;You haven't clarified your question enough. Are you strings values in a data set? Are they in a macro variable?&lt;BR /&gt;What do you the macro variable created to be? What are you going to use it for?&lt;/P&gt;</description>
      <pubDate>Tue, 25 Oct 2022 20:33:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840678#M332404</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-10-25T20:33:00Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting character strings whose last 3 characters ends with certain characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840822#M332453</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input string $;
cards;
20012
24012
20021
28021
20040
;

%let valid = 012 040 ;
data want;
    set have;
    if findw("&amp;amp;valid",strip(substrn(string,length(string)-2)));
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 26 Oct 2022 11:36:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840822#M332453</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2022-10-26T11:36:00Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting character strings whose last 3 characters ends with certain characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840861#M332473</link>
      <description>&lt;P&gt;Thank you for your suggestion.&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is a part of a macro, so I have use %let.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll incorporate your suggestion to something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%let valid = ;&lt;/P&gt;&lt;P&gt;data _null_;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;if left(reverse(string)) in :('210','040') then output;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I hope this works.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Yoko&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 13:01:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840861#M332473</guid>
      <dc:creator>Yoko</dc:creator>
      <dc:date>2022-10-26T13:01:51Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting character strings whose last 3 characters ends with certain characters</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840864#M332474</link>
      <description>&lt;P&gt;A macro solution could be obtained by marrying the wonderful %sysfunc() and prx*() functions. This works for me:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=20040;
%let regex=/012$|040$/;
%let regid=%sysfunc(prxparse(&amp;amp;regex));
%put &amp;amp;=regid;
%let valid = %sysfunc(prxmatch(&amp;amp;regid, &amp;amp;string));
%put &amp;amp;=valid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The code could be further condensed but this is the most descriptive.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let string=20040;
%let valid = %sysfunc(prxmatch(/012$|040$/, &amp;amp;string));
%put &amp;amp;=valid;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The macro variable "valid" has a value of 0 (zero) if there is no match or a positive integer indicating startposition of the pattern searched for.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Needless to say I am a fan of the prx functions and highly recommend them in these situations.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps,&lt;/P&gt;
&lt;P&gt;- Jan.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Oct 2022 13:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-character-strings-whose-last-3-characters-ends-with/m-p/840864#M332474</guid>
      <dc:creator>jklaverstijn</dc:creator>
      <dc:date>2022-10-26T13:06:18Z</dc:date>
    </item>
  </channel>
</rss>

