You can do this with a regular expression
data have;
string="fhwfwoeuh, 12314, fjweipfjwp 214155";output;
string="Hello, 112345 Joifhew, 12-08-2017";output;
string="12343 dfnweon 12.08.17";output;
string="978y 12343 dfnweon 12.08.17";output;
run;
data want(keep=string firstnumber);
set have;
if _n_=1 then prx=prxparse("/\d{5,}/");
call prxsubstr(prx,string,start,length);
if start > 0 then do;
firstnumber=substr(string,start,length);
output;
end;
retain prx;
run;
I've added an extra record where the first occurrence is only 3 digits so it picks up the second occurrence in that string for testing.
The regular expression \d{5,} looks for at least five digits and call prxsubstr is used to extract those cases where a match is found
... View more