Hello Community!
I was trying to extract string between parenthesis and using regular expression. I was able to extract the first occurrence, but want all the values if multiple parenthesis exists.
data have;
infile datalines truncover;
length char_var $100.;
input char_var $1-100;
if _n_=1 then do;
retain re;
re = prxparse('/\(([^()]*)\)/'); /* How to define my pattern here?*/
if missing(re) then do;
putlog 'ERROR: regex is malformed';
stop;
end;
end;
if prxmatch(re,char_var) then do; char_var_new = prxchange('s/\(([^\)]+)\)//i',-1,char_var); /* I want all the values that were removed here */
code1 = prxposn( re, 1, char_var);
code2 = prxposn( re, 2, char_var);
/* call prxposn( re, 1, endgstart, endglen);*/
/* code = substr(char_var,endgstart,endglen);*/
output;
end;
datalines;
1111, 2222 (0000)
1111 (11, 22, 33, 44)
90658
11(00),33(111)
;
run;
... View more