BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
BlayLay
Obsidian | Level 7

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:

 

SerialCurrentSerialNew
A00589F123456A00589F
BT10346T145326BT10346T
AK00H20078354AK00H
LM01T234578LM01T

 

Any and all help would be greatly appreciated!

 

Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
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;

View solution in original post

2 REPLIES 2
novinosrin
Tourmaline | Level 20
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;
BlayLay
Obsidian | Level 7
Works perfectly! Thank you!

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

How to Concatenate Values

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 955 views
  • 1 like
  • 2 in conversation