我想从SAS中的原始字符串中删除字符串列表

时间:2016-08-31 09:47:46

标签: sas

我想删除" LIMITED"," LTD"," CORPORATION"," GMBH"," AG&#34 ;," SDN"," BHD"," INC"来自我的Customer_Name变量的字符串。 我试过在SAS中使用压缩功能 Customer_Name1 = compress(Customer_Name,' LIMITED',' LTD'' GMBH');

但我收到错误 -

  

COMPRESS函数调用有太多参数。

请提出解决方法。

1 个答案:

答案 0 :(得分:1)

我会使用正则表达式来执行此操作。将要删除的单词存储在宏变量中,然后使用call prxchange在名称中进行搜索并将其删除。单词由|分隔,表示正则表达式语言中的or

%let vals = LIMITED|LTD|CORPORATION|GMBH|AG|SDN|BHD|INC;

data have;
input name $20.;
datalines;
a ltd
b limited
c corporation
d corp
e gmbh
f test
g ag
i sdn
j bhd
aggregate ag
income inc
;
run;

data want;
set have;
regex = prxparse("s/\b(&vals.)\b//i"); /* /b signifies a word boundary, so it will remove the whole words only */
call prxchange(regex,-1,name);
drop regex;
run;