This may be close.
data example;
infile cards truncover;
input text $100.;
if _n_ eq 1 then do;
/* Pattern to remove digit strings that are not part of a word */
pattern_all_digits = prxparse("s/\b\d+\b//");
/* Pattern to detect digit strings at the beginning of the sentence */
pattern_leading_digits = prxparse("/^\d+/");
retain pattern_:;
end;
/* Initialize variables */
new_text = text;
/* Check for leading digits and preserve them if found */
if prxmatch(pattern_leading_digits, text) then do;
length leading_digits $20.;
call prxsubstr(pattern_leading_digits, text, position, length);
leading_digits = substr(text, position, length);
new_text = prxchange(pattern_all_digits, -1, substr(text, length+1));
new_text = catx(' ', leading_digits, new_text);
end;
else do;
new_text = prxchange(pattern_all_digits, -1, text);
end;
drop pattern_all_digits pattern_leading_digits position length leading_digits;
datalines;
123 Here are some numbers: 123, 456, and 789.
This string has no numbers.
42 A single number: 42.
More numbers: 333, 7777.
99 Another example 100 200.
abc123def Keep digits in words like abc123def.
123abc Also keep digits in words like 123abc.
;
run;
proc print data=example;
run;
@sam88r wrote:
I really appreciate your help. Would it possible to adjust the code to not to remove the digits in these kind of scenarios?
Ex: XXX1222 YYYY, SSS1222 TYYYY 1222
the outputs of these kind of scenarios would be :
XXX1222 YYYY, SSS1222 TYYYY
... View more