Hi Everyone,
I have a SAS dataset, with a column we can call SerialCurrent for this exercise. There are several hundred unique serial numbers within the column, all with varying lengths (trim based on # of positions isn't an option, nor by unique character). Each record is a string that varies in letters used and length. What I'm trying to do is to eliminate ALL numbers after the LAST letter in each string. Example below shows what is currently showing and I've added a second column for you to see what I'm trying to get to:
| SerialCurrent | SerialNew |
| A00589F123456 | A00589F |
| BT10346T145326 | BT10346T |
| AK00H20078354 | AK00H |
| LM01T234578 | LM01T |
Any and all help would be greatly appreciated!
Thanks
data have;
input SerialCurrent :$30. ;*SerialNew;
cards;
A00589F123456 A00589F
BT10346T145326 BT10346T
AK00H20078354 AK00H
LM01T234578 LM01T
;
data want;
set have;
SerialNew=substr(serialcurrent,1,notdigit(strip(serialcurrent),-99));
run;
data have;
input SerialCurrent :$30. ;*SerialNew;
cards;
A00589F123456 A00589F
BT10346T145326 BT10346T
AK00H20078354 AK00H
LM01T234578 LM01T
;
data want;
set have;
SerialNew=substr(serialcurrent,1,notdigit(strip(serialcurrent),-99));
run;
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.