如何将变量访问中包含“电话跟进W”的值更改为“跟进W”?

时间:2019-07-17 10:00:31

标签: regex sas

在这里,我得到一个名为“ VISIT”的变量。我想将“电话跟进W *”之类的所有值更改为“跟进W *”之类的值。或者我们可以说,从“ Phone Follow-Up W *”之类的值中删除字符串“ Phone”。

VISIT:

Additional Phone Follow-Up 
Enrollment
Visit 2
Visit 3
Visit 4
Visit 5
Visit 6
Visit 7
Visit 8
Phone Follow-Up W28
Phone Follow-Up W32
Visit 9
Phone Follow-Up W40
Phone Follow-Up W44
Phone Follow-Up W48
EOT
Phone Follow-Up W56
Phone Follow-Up W60
EOS

我尝试了如下代码,但是出现了错误。

data test4;
   set test2
   REX_Id = prxparse('s/Phone Follow-Up W/Follow-Up W/');
   call prxchange(REX_Id, -1, VISIT);
run;

我希望得到如下结果,除了“附加电话跟踪”中的第一个电话字符串外,所有字符串“电话”都将被删除。

VISIT:

Additional Phone Follow-Up
Enrollment
Visit 2
Visit 3
Visit 4
Visit 5
Visit 6
Visit 7
Visit 8
Follow-Up W28
Follow-Up W32
Visit 9
Follow-Up W40
Follow-Up W44
Follow-Up W48
EOT
Follow-Up W56
Follow-Up W60
EOS

2 个答案:

答案 0 :(得分:2)

如果您想使用正则表达式来更改字符串中等于 Phone 的第一个单词:

data test4;
   set test2;
   REX_Id = prxparse('s/^(?<=\s)*(Phone )//');
   call prxchange(REX_Id, -1, VISIT);
run;

答案 1 :(得分:1)

假设您只想在字符串开头出现“电话”一词时删除,则可以执行以下操作:

if index(strip(visit), "Phone ") = 1 then visit = substr(strip(visit), 7);