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
Ammonite | Level 13

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