|
|
6#

楼主 |
发表于 2010-4-8 17:47:07
|
只看该作者
Re: 如何从表达式中提取变量
那我就来个正则表达式版本的吧..
[code:1ih262qw]data v;
length s $50.;
s="age2~=";
output;
s='_age>60 ';
output;
s='age>60 And sex=1';
output;
s='time1-time0>time24';
output;
run;
data prx_v;
set v;
length v $50;
RE = prxparse("/(\W*)(\w+)(\W*)/");
do while (^missing(s));
position = prxmatch(RE, s);
if position ^= 0 then
do;
call prxposn(RE, 2, start, length);
if start ^= 0 then v = substr(s, start, length);
call prxposn(RE, 3, start, length);
s = substr(s, start + length);
if lowcase(v) not in ('not', 'and', 'or', 'eq', 'ne', 'gt', 'ge', 'lt', 'le', 'in')
and anydigit(v) ~= 1
then output;
end;
end;
prxfree(RE);
keep v;
run;
[/code:1ih262qw] |
|