如何从sas中的混合变量列表(num + char)中仅提取字符值
How to extract only character values from a mixed variable list(num+char) in sas
在变量列表中有数字和字符值,我怎样才能在 sas 中只从中获取字符值。示例数据线在这里只有一个变量列表 VAR1 有值例如:
123
xyz
457
abc
789
frf
233
gth
...
664
fgd
我必须从整个数据行中只提取那些字符值(abc、xyz 等),我怎样才能得到。
看看你能不能用这个
data _null_;
var1 = '123, xyz, 456, abc, 789, frf, 233, gth';
var2 = compbl(compress(var1, '', 'ka'));
put var2=;
run;
编辑:
data _null_;
var1 = '123 xyz 456 abc 789 frf 233 gth
123 xyz 456 abc 789 frf 233 gth
123 xyz 456 abc 789 frf 233 gth';
var2 = compbl(compress(var1, '', 'ka'));
put var2;
run;
这个问题不是很清楚,但是,如果各个值在单个列中,您可以使用 VERIFY
而不是更复杂的 PRXMATCH
data have;
input var1 $; datalines;
123
xyz
457
abc
789
frf
233
gth
...
664
fgd
;
data want;
set have;
where 0 = verify (trim(var1), '0123456789');
run;
Returns the position of the first character in a string that is not in specified data strings.
...
Details
The VERIFY function returns the position of the first character in source that is not present in any excerpt. If VERIFY finds every character in source in at least one excerpt, VERIFY returns a 0.
这段代码对我来说工作正常:
数据需要;
设置有;
如果 prxmatch('/\d+\s*$/',VAR1)>0 则删除;
运行;
在变量列表中有数字和字符值,我怎样才能在 sas 中只从中获取字符值。示例数据线在这里只有一个变量列表 VAR1 有值例如:
123
xyz
457
abc
789
frf
233
gth
...
664
fgd
我必须从整个数据行中只提取那些字符值(abc、xyz 等),我怎样才能得到。
看看你能不能用这个
data _null_;
var1 = '123, xyz, 456, abc, 789, frf, 233, gth';
var2 = compbl(compress(var1, '', 'ka'));
put var2=;
run;
编辑:
data _null_;
var1 = '123 xyz 456 abc 789 frf 233 gth
123 xyz 456 abc 789 frf 233 gth
123 xyz 456 abc 789 frf 233 gth';
var2 = compbl(compress(var1, '', 'ka'));
put var2;
run;
这个问题不是很清楚,但是,如果各个值在单个列中,您可以使用 VERIFY
而不是更复杂的 PRXMATCH
data have;
input var1 $; datalines;
123
xyz
457
abc
789
frf
233
gth
...
664
fgd
;
data want;
set have;
where 0 = verify (trim(var1), '0123456789');
run;
Returns the position of the first character in a string that is not in specified data strings. ...
Details
The VERIFY function returns the position of the first character in source that is not present in any excerpt. If VERIFY finds every character in source in at least one excerpt, VERIFY returns a 0.
这段代码对我来说工作正常: 数据需要; 设置有; 如果 prxmatch('/\d+\s*$/',VAR1)>0 则删除; 运行;