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-white.png

🚨 Early Bird Rate Extended!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Lock in the best rate now before the price increases on April 1.

Register now!

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
  • 1 reply
  • 458 views
  • 1 like
  • 2 in conversation