<?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: Last 5 characters from string (irrespective of the length) in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182258#M34726</link>
    <description>&lt;P&gt;Depends if NUMBER is a number or a character string.&lt;/P&gt;
&lt;P&gt;Try these methods.&amp;nbsp; What do you want to do when the number is already less than 5 digits?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;data have ;
 /* Read as both a number and a char */
&amp;nbsp; input @1 number @1 char $10. ;
  /* calc 5 digit remainder with mod() */
&amp;nbsp; number2 = mod(number,100000);
  /* for char version, get last 5 characters */
&amp;nbsp; char2 = substr(right(char),6);
  /* handle case when char &amp;lt; 5 digits */
&amp;nbsp; char3 = substr(char,max(1,length(char)-4));
&amp;nbsp; put number number2 char2 char3 ;
cards;
1234567890
123456
987654321
8888888
999999999
4242424
1234
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt;Obs        number    char          number2    char2    char3

 1     1234567890    1234567890     67890     67890    67890
 2         123456    123456         23456     23456    23456
 3      987654321    987654321      54321     54321    54321
 4        8888888    8888888        88888     88888    88888
 5      999999999    999999999      99999     99999    99999
 6        4242424    4242424        42424     42424    42424
 7           1234    1234            1234      1234    1234 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Feb 2017 13:15:44 GMT</pubDate>
    <dc:creator>Tom</dc:creator>
    <dc:date>2017-02-28T13:15:44Z</dc:date>
    <item>
      <title>Last 5 characters from string (irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182256#M34724</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me with Syntax&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;/* How to take last 5 characters from a string */&lt;/P&gt;
&lt;P&gt;Ex:-&lt;/P&gt;
&lt;P&gt;Number in Text&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Number&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;1234567890
123456
987654321
8888888
999999999
4242424&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output should be like&lt;/P&gt;
&lt;P&gt;Number&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;67890
23456
54321
88888
99999
42424&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Appriciate in advance&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 12:58:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182256#M34724</guid>
      <dc:creator>sas_lak</dc:creator>
      <dc:date>2017-02-28T12:58:47Z</dc:date>
    </item>
    <item>
      <title>Re: Last 5 characters from string(irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182257#M34725</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How about this?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;DATA WANT;&lt;/P&gt;&lt;P&gt;SET HAVE;&lt;/P&gt;&lt;P&gt;NUMBER1 = SUBSTR(TRIM(NUMBER),LENGTH(TRIM(NUMBER))-4);&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 17 Jul 2014 06:19:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182257#M34725</guid>
      <dc:creator>Scott_Mitchell</dc:creator>
      <dc:date>2014-07-17T06:19:20Z</dc:date>
    </item>
    <item>
      <title>Re: Last 5 characters from string (irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182258#M34726</link>
      <description>&lt;P&gt;Depends if NUMBER is a number or a character string.&lt;/P&gt;
&lt;P&gt;Try these methods.&amp;nbsp; What do you want to do when the number is already less than 5 digits?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&amp;nbsp;data have ;
 /* Read as both a number and a char */
&amp;nbsp; input @1 number @1 char $10. ;
  /* calc 5 digit remainder with mod() */
&amp;nbsp; number2 = mod(number,100000);
  /* for char version, get last 5 characters */
&amp;nbsp; char2 = substr(right(char),6);
  /* handle case when char &amp;lt; 5 digits */
&amp;nbsp; char3 = substr(char,max(1,length(char)-4));
&amp;nbsp; put number number2 char2 char3 ;
cards;
1234567890
123456
987654321
8888888
999999999
4242424
1234
;;;;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Output:&lt;/P&gt;
&lt;PRE&gt;Obs        number    char          number2    char2    char3

 1     1234567890    1234567890     67890     67890    67890
 2         123456    123456         23456     23456    23456
 3      987654321    987654321      54321     54321    54321
 4        8888888    8888888        88888     88888    88888
 5      999999999    999999999      99999     99999    99999
 6        4242424    4242424        42424     42424    42424
 7           1234    1234            1234      1234    1234 
&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Feb 2017 13:15:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182258#M34726</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-02-28T13:15:44Z</dc:date>
    </item>
    <item>
      <title>Re: Last 5 characters from string(irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182259#M34727</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here is another proposal:&lt;/P&gt;&lt;P&gt;&lt;SPAN lang="EN-US" style="font-family: 'Times New Roman','serif'; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;input&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; char $char20.;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;cards&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt;1234567890&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt;&amp;nbsp;&amp;nbsp; 123456&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt; 987654321 &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt;8888888&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt;999999999&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: #ffffc0; color: black; font-size: 12pt;"&gt;4242424&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;data&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; want;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;set&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; have;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;length&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; char_new $&lt;/SPAN&gt;&lt;STRONG style="color: teal; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;5&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; char_new=left(reverse(char));&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; char_new=reverse(char_new);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;proc&lt;/STRONG&gt; &lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;print&lt;/STRONG&gt; &lt;SPAN style="font-family: 'Courier New'; background: white; color: blue; font-size: 12pt;"&gt;data&lt;/SPAN&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;=want; &lt;/SPAN&gt;&lt;STRONG style="color: navy; font-size: 12pt; background: white; font-family: 'Courier New';"&gt;run&lt;/STRONG&gt;&lt;SPAN style="font-family: 'Courier New'; background: white; color: black; font-size: 12pt;"&gt;;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 08:34:34 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182259#M34727</guid>
      <dc:creator>barchan</dc:creator>
      <dc:date>2014-07-18T08:34:34Z</dc:date>
    </item>
    <item>
      <title>Re: Last 5 characters from string(irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182260#M34728</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Mmm, nice, but it does have leading blanks if your string isn't &amp;gt; 5 in the first place.&amp;nbsp; Also, if you have a long program (and maybe if length isn't even setup there), its not easy to see what is happening as the code just reverses twice.&amp;nbsp; Substr or trimming make the statement very explicit.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 09:00:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182260#M34728</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2014-07-18T09:00:56Z</dc:date>
    </item>
    <item>
      <title>Re: Last 5 characters from string(irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182261#M34729</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;Try this&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;&amp;nbsp; input number $;&lt;/P&gt;&lt;P&gt;&amp;nbsp; var = substr(number,length(number)-4);&lt;/P&gt;&lt;P&gt;cards;&lt;/P&gt;&lt;P&gt;1234567890&lt;/P&gt;&lt;P&gt;123456&lt;/P&gt;&lt;P&gt;987654321&lt;/P&gt;&lt;P&gt;8888888&lt;/P&gt;&lt;P&gt;999999999&lt;/P&gt;&lt;P&gt;4242424&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 09:06:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182261#M34729</guid>
      <dc:creator>SanjayAhir</dc:creator>
      <dc:date>2014-07-18T09:06:33Z</dc:date>
    </item>
    <item>
      <title>Re: Last 5 characters from string(irrespective of the length)</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182262#M34730</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;string=prxchange('s/.*(\d{5})/$1/',-1,strip(number));&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 18 Jul 2014 13:23:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Last-5-characters-from-string-irrespective-of-the-length/m-p/182262#M34730</guid>
      <dc:creator>slchen</dc:creator>
      <dc:date>2014-07-18T13:23:52Z</dc:date>
    </item>
  </channel>
</rss>

