BookmarkSubscribeRSS Feed
Lando_Griffen
Calcite | Level 5
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
4 REPLIES 4
Cynthia_sas
Diamond | Level 26
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
Lando_Griffen
Calcite | Level 5
Thanks. You can probably tell I'm new at this. I appreciate your help.
sbb
Lapis Lazuli | Level 10 sbb
Lapis Lazuli | Level 10
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;

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

Creating Custom Steps in SAS Studio

Check out this tutorial series to learn how to build your own steps in SAS Studio.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1669 views
  • 0 likes
  • 4 in conversation