Hello SASPhile,
Here is how your program could look like:
data T01_input;
length drug $50;
infile cards delimiter=',';
input id drug;
cards;
1,Paracetmol 4.8MG VIA
2,Paracetmol 423.23422238MG VIA
3,Paracetmol 42342.38MG VIA
4,Paracetmol x.8MG VIA
;
run;
data T02_output;
set T01_input;
length myDigits $50;
if prxmatch('/.* \d{1,4}\.\d+MG .*/',drug)
then myDigits = prxchange('s/.* (\d{1,4}\.\d+)MG .*/$1/', -1, drug);
else myDigits = "NOT FOUND";
run;
proc print data=T02_output;
run;
You would get the following output:
1 Paracetmol 4.8MG VIA 1 4.8
2 Paracetmol 423.23422238MG VIA 2 423.23422238
3 Paracetmol 42342.38MG VIA 3 NOT FOUND
4 Paracetmol x.8MG VIA 4 NOT FOUND
If you need to convert the myDigit string to number ... use the input function.
Does it help?
Yoba