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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.