SAS中的正则表达式读取:
是否发生器械缺陷(If any DD exist)(code)中每一个括号中的内容。用prxposn只能读取一个括号中的内容,用prxnext可以循环读取括号中的内容。
data a;
input var& $ 50.;
cards;
是否发生器械缺陷(If any DD exist)(code)
;
run;
data b;
set a;
re=prxparse("/\((.*?)\)/");
_start = 1;
_stop = length(var);
call prxnext(re, _start, _stop, var, _pos, _len);
/* _pos, _len是查找过程中SAS生成的值并保存在这两个变量中*/
if _pos<=0 then output;
else do while (_pos > 0);
found = substr(var, _pos, _len);
put found= _pos= _len=;
output;
call prxnext(re, _start, _stop, var, _pos, _len);
end;
run;