Hi,
This is a totally old school example, using INDEX and COMPRESS but I threw in PRXMATCH(see below) to compare to INDEX and both PRXMATCH and INDEX return the same results (if you compare FOUNDIT and FOUNDIT2). The COMPRESS/SUBSTR is not as elegant as the other solution but it does the job.
cynthia
[pre]
data prxtest;
length grp $1 string $100;
infile datalines dsd dlm=',';
input grp $ string $;
return;
datalines;
a,"The 1st Incident was when 12345 (Mr. Dumpty) fell off the wall."
b,"The 2nd Incident was when 34567 (Ms. Muffet) fell off a stool."
c,"Has the 123 word Incident, but there are no numbers after 'Incident'."
;
run;
proc print data=prxtest;
title 'What does the data look like';
run;
data checkdata;
length gotnum 8.;
set prxtest;
retain lookfor ;
if _n_=1 then do;
** Create pattern with prxparse.;
lookfor = prxparse('/Incident/');
end;
** Prxmatch returns the location in Arg2,;
** where ARG1 begins.;
** Note how prxmatch and index return the same number;
** Do you really need prxparse/prxmatch?;
** Will Index function work for your data?;
foundit = prxmatch(lookfor,string);
foundit2 = index(string,'Incident');
** If the pattern has been found;
** substring out everything AFTER;
** the word "Incident". Then, compress;
** out the punctuation and upper and lower case letters.;
** What should be left are the numbers after the string Incident.;
if foundit gt 0 then do;
gotnum = input((compress(substr(string,foundit+8),'.,;:()','al')),8.0);
end;
else do;
gotnum = .;
end;
run;
proc print data=checkdata;
title 'Found "Incident" Got number';
run;
[/pre]