<?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 Extract the last character of a string / Extract only numeric values in an alphanumeric string in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292328#M60657</link>
    <description>&lt;P&gt;#1. I have a variable that contains alphanumeric strings of differing lengths. The last digit in each string is a character. I need to extract just the last digit of each string into a new variable. I was trying to use the SUBST function, but I don't know how to determine the position when the length of the string may change from observation to observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#2. Then, I need to extract only the numeric values in this same variable (e.g.&amp;nbsp;xyz1333520M, x1234F). Again, the&amp;nbsp;alphanumeric strings are of differing lengths. How can I extract just the numeric values (They are always sequential).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
    <pubDate>Thu, 18 Aug 2016 01:35:47 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2016-08-18T01:35:47Z</dc:date>
    <item>
      <title>Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292328#M60657</link>
      <description>&lt;P&gt;#1. I have a variable that contains alphanumeric strings of differing lengths. The last digit in each string is a character. I need to extract just the last digit of each string into a new variable. I was trying to use the SUBST function, but I don't know how to determine the position when the length of the string may change from observation to observation.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;#2. Then, I need to extract only the numeric values in this same variable (e.g.&amp;nbsp;xyz1333520M, x1234F). Again, the&amp;nbsp;alphanumeric strings are of differing lengths. How can I extract just the numeric values (They are always sequential).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 01:35:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292328#M60657</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-08-18T01:35:47Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292329#M60658</link>
      <description>&lt;P&gt;1. Reverse(substr(string,1,1))&lt;/P&gt;
&lt;P&gt;2. Compress(string, , 'kd');&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Check the parameter order for compress, but use the modifiers to keep only digits&lt;/P&gt;</description>
      <pubDate>Thu, 18 Aug 2016 01:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292329#M60658</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-18T01:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292337#M60660</link>
      <description>&lt;P&gt;The LENGTH() function will tell you the location of the last non-blank character. &amp;nbsp;(Note for empty strings it will return 1).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;want = substr(have,length(have),1);
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 02:49:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292337#M60660</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-08-18T02:49:39Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292361#M60676</link>
      <description>&lt;PRE&gt;
Then use LENGTHN()


data _null_;
x='xxx';n1=length(x);n2=lengthn(x);
put x= n1= n2=;

x=' ';n1=length(x);n2=lengthn(x);
put x= n1= n2=;

run;

&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Aug 2016 05:28:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292361#M60676</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2016-08-18T05:28:05Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292859#M60860</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The result for Reverse(substr(string,1,1)) is the same as the result for (substr(string,1,1)). It seems like it's not picking up the "reverse".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What am I doing wrong here?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 21:48:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292859#M60860</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-08-19T21:48:25Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292860#M60861</link>
      <description>&lt;P&gt;Reverse the string and then take the substring.&lt;/P&gt;
&lt;P&gt;Reversing a string of 1 is 1.&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 21:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292860#M60861</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-19T21:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292861#M60862</link>
      <description>&lt;P&gt;If the string is only one character string long then reversing it does nothing.&lt;/P&gt;
&lt;P&gt;But if you applied the functions&amp;nbsp;in the other order then you could still have problems because of&amp;nbsp;trailing spaces. If you store 'ABC' into variable of length 5 then it will have two trailing spaces. If you reverse it there will be two leading spaces instead.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;substr(reverse(trim(VAR)),1,1)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But it does seem like way too much work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 19 Aug 2016 22:01:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292861#M60862</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2016-08-19T22:01:42Z</dc:date>
    </item>
    <item>
      <title>Re: Extract the last character of a string / Extract only numeric values in an alphanumeric string</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292866#M60863</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;lt;Reverse the string and then take the substring.&amp;nbsp;Reversing a string of 1 is 1.&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I understand the approach, but: 1) The strings are not 1 character in length (e.g. 13000M, x13260M); and 2) When the string is reversed, the syntax is still taking the character in the first position in the orginal, not reversed, string.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;In other words,&amp;nbsp;13000M is new_var=1, both with, and without, the reverse function. Should new_var=M, given that the string was reversed? That's what I'm after...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When I use the functions separately the reverse function converts&amp;nbsp;13000M to&amp;nbsp;M13000. When I then use the substring function, only a subset of the observations have the correct value. It's only the observations w/ the longest length (i.e. 7 characters).&amp;nbsp;Any observation w/ less characters than that contains a missing value (See attached image).&lt;/P&gt;&lt;BR /&gt;&lt;IMG src="https://communities.sas.com/t5/image/serverpage/image-id/12862i8867E355CB17607A/image-size/large?v=1.0&amp;amp;px=600" border="0" alt="rev sub.jpg" title="rev sub.jpg" /&gt;</description>
      <pubDate>Fri, 19 Aug 2016 23:12:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Extract-the-last-character-of-a-string-Extract-only-numeric/m-p/292866#M60863</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2016-08-19T23:12:26Z</dc:date>
    </item>
  </channel>
</rss>

