SAS:宏:子串和替换

时间:2012-07-12 10:19:17

标签: macros sas substr

我有两个简单的宏:

%macro One(mvStr);
      /*some code here to replace varOne -> stringOne*/     

%mend One;

%macro Two;
    %local mvStr;
    %let mvStr = "String varOne StringvarOneString";
    %One(&mvStr);
%mend Two;

那么,如何用varOne替换所有子串stringOne

2 个答案:

答案 0 :(得分:2)

这应该做你想要的......

%macro One(mvStr);
  /*some code here to replace varOne -> stringOne*/     
  %Sysfunc(tranwrd(&mvStr, varOne, StringOne));
%mend One;

%macro Two;
    %local mvStr;
    %let mvStr = "String varOne StringvarOneString";
    %let mvStr = %One(&mvStr);

    %put &mvStr; 
%mend Two;

%two;

答案 1 :(得分:0)

Did not know if you have to have two macros, but would the following suffice?


%macro one(mvStr, From, To);
  %local mvStr From To;
  %let &mvStr. = "String &From. String&From.String";
  %put  %Qsysfunc(prxchange(s/&From./&To./,-1,&mvStr.));
  %*put &mvStr.; 
%mend;

options mprint;
%one(mvStr,varOne,StringOne)