data ex;
input comments:& $200.;
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;
Qsn: How to extract last number without regex method
output
marks
90
1 00
30
data ex;
input comments:& $200.;
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;
data test;
set ex;
do i=1 to countw(comments, '');
word = scan(comments, i, ' ', 'b');
if ^notdigit(strip(word)) then do;
put word=;
leave;
end;
end;
run;
Hi, Can you try this?
data ex;
input comments:& $200.;
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;
data test;
set ex;
do i=1 to countw(comments, '');
word = scan(comments, i, ' ', 'b');
if ^notdigit(strip(word)) then do;
put word=;
leave;
end;
end;
run;
Hi, Can you try this?
data ex;
input comments:& $200.;
want=scan(comments,-1,,'kd');
Cards;
1Ram scored 90 marks
2seetha has got 100
3Laxman failed with 30 in English
;
proc print;
run;
Hi @Ksharp
Thank you very much for your solution
Hi @Astounding ,
As per your question
data ds;
input text :& $ 200.;
want=scan(text,-1,,'kd');
cards;
A89 90
4 a1b2c
a44bcc3
22bsi44-5c
9tt$b21t88
;
proc print;
run;
i can use Scan function with 'kd' modifier
PFabove
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.