xulimei1986 发表于 2014-10-15 09:17 
不好意思,原数据为
12126789
X的值只包括数字
楼主可以试一下这个:
data wanted;
set test;
do i=1 to length(x)-3;
call missing(rule);
_1st=input(substr(x,i,1),best.);
_2nd=input(substr(x,i+1,1),best.);
_former2=input(substr(x,i,2),best.);
_latter2=input(substr(x,i+2,2),best.);
if _1st = _2nd and _former2 = _latter2 then rule=1;
else if _1st ^= _2nd and _former2 = _latter2 then rule=2;
else if _2nd - _1st = 1 and _latter2 - _former2 = 22 then rule=3;
if ^missing(rule) then do;
rule_num=substr(x,i,4);
output;
end;
end;
drop _: i;
run;