BookmarkSubscribeRSS Feed
Feyng819
Obsidian | Level 7
Let’s say I have an alphanumeric string of “abcdef123ghi”, how can I extract and get up till the last digit of the string “abcdef123”? I was trying to find the location of the last digit using find and reverse, and use substr to extract it but it doesn’t work. Thanks for your help in advance
1 REPLY 1
SASJedi
SAS Super FREQ

Try SUBSTR with ANYDIGIT:

data _null_;
	string="abcdef123ghi";
	want=substr(string,1,anydigit(string,-9999));
	put string= want=;
run;

https://go.documentation.sas.com/doc/en/pgmsascdc/v_048/lefunctionsref/p0gq8bwobt4wjgn12km94wi66mxw....  

Check out my Jedi SAS Tricks for SAS Users

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 1 reply
  • 319 views
  • 1 like
  • 2 in conversation