Well:
data want;
set have;
do i=1 to countw(mystring,"#");
if scan(mystring,i,"#") ne "." then last_num=scan(mystring,i,"#");
end;
run;
Below should do the job.
data have;
length string $100;
string="#113#468#9999#2474#.#.#.#.#";output;
string="5743#788#1#9#89999#64#68#.#.#";output;
string="#.#.#";output;
string="#.#.#123";output;
string="456#.#.#";output;
run;
data want;
set have;
number=input(scan(string,-1,,'kd'),best32.);
run;
Well:
data want;
set have;
do i=1 to countw(mystring,"#");
if scan(mystring,i,"#") ne "." then last_num=scan(mystring,i,"#");
end;
run;
are your digits always surrounded by ##?
An alternative..
data have;
length string $100;
string="#113#468#9999#2474#.#.#.#.#";output;
string="5743#788#1#9#89999#64#68#.#.#";output;
run;
data want;
set have;
to=anydigit(string, -length(string));
from=notdigit(string, -to)+1;
num=substr(string, from, to-from+1);
run;
Thanks for all your help. So many solutions!
No loop needed for your examples, very simple and straight forward-->
data want;
mystring="#113#468#9999#2474#.#.#.#.#";
last_num=scan(compress(mystring,'.'),-1,'#');
output;
mystring="5743#788#1#9#89999#64#68#.#.#";
last_num=scan(compress(mystring,'.'),-1,'#');
output;
run;
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.