Desktop productivity for business analysts and programmers

Returning Right/left side # of characters from column

Reply
New Contributor
Posts: 4

Returning Right/left side # of characters from column

In excel is a feature to extract a requested number of characters (left or right) of a column into a new column.
ie, if column a1 had 9009125439
the formula would look like
=right(a1,5)
which would give a result of 25439.
according to what I saw the RIGHT/LEFT function in eg only realigns the column.
I need to know how/if the right/left excel function can be done in eg. Thanks
Contributor
Posts: 30

Re: Returning Right/left side # of characters from column

try substr()
SAS Super FREQ
Posts: 8,720

Re: Returning Right/left side # of characters from column

Also investigate SUBSTR with the PUT function. If your variable is CHARACTER, then you won't need the PUT function. If your variable is numeric, and large, then you might want to use an explicit PUT function so you can control how the number is converted from numeric to character. SUBSTR only works on character variables.

cynthia
New Contributor
Posts: 4

Re: Returning Right/left side # of characters from column

Thanks. You can probably tell I'm new at this. I appreciate your help.
Super Contributor
Super Contributor
Posts: 3,174

Re: Returning Right/left side # of characters from column

Here are a couple of examples, one using SUBSTR and LENGTH functions, and the second approach using SUBSTR with REVERSE.

Scott Barry
SBBWorks, Inc.


data _null_;
retain x 'aaabbb ';
y = substr(x,length(x)-2,3);
z = reverse(substr(reverse(trim(x)),1,3));
putlog _all_;
run;
Ask a Question
Discussion stats
  • 4 replies
  • 119 views
  • 0 likes
  • 4 in conversation