Here's another Perl Regular Expression example, I basically hacked this example in the documentation
data have;
length id $10 dcode $48;
input id$ dcode$ &;
datalines;
1 I410 J332
2 C450 I412
3 I413 R789 I412 I4123
4 R281 I519 I413 I51698
5 O603 C351
;
run;
data want ;
retain re 0 ;
if _n_=1 then do ;
re=prxparse('/I41\w*|I51\w*/') ;
end ;
set have ;
x=prxmatch(re,dcode) ;
start=1 ;
stop=length(dcode) ;
call prxnext(re,start,stop,dcode,position,length) ;
do while(position>0) ;
found=substr(dcode,position,length) ;
call prxnext(re,start,stop,dcode,position,length) ;
put found= ;
output ;
end ;
run ;
... View more