11-19-2014 12:53 PM
Im trying to keep the last letter of a text string that has various lengths in order to create a new variable.
The example is below
So all i need is just the last character.
11-19-2014 01:51 PM
Gosh you folks are fast...
From Cody's SAS Functions by Example:
input charvar1 $;
LastChar = substr(charvar1,length(charvar1),1);
11-19-2014 03:34 PM
A couple of hidden "features" here ...
Note that LENGTH never returns 0. If the incoming string is blank, it returns 1 so the second argument to SUBSTR will still be valid.
Also note that the LENGTH statement should be added. When SUBSTR creates a new variable, the length will not be $1, but will be the length of the original string. You can easily see that by running a PROC CONTENTS.
11-19-2014 10:13 PM
input charvar1 $ 8.;
lastchar=prxchange('s/(.+)([a-zA-Z])$/$2/o', -1, trim(charvar1));
11-19-2014 10:51 PM
Let me count the ways...the number on the end of the REVERS format must be at least as long as the input variable
a = 'ABCD ';
attrib LastChar length= $1;
LastChar = put(a, $REVERS100.);
Need further help from the community? Please ask a new question.