在proc sql中替换一个宏变量的字符串

时间:2014-09-12 15:36:56

标签: sas sas-macro proc-sql

在Proc SQL中,我想使用宏变量&condition3,但我想在宏变量中用“t6”替换字符串“t1”。如何使以下公式起作用:translate(&condition3,'T6','T1')

顺便说一下,&condition3解析为:and t1.store in ('1234')

完整查询:

Proc sql;
  Create table xxx as
    Select....
      From ...
      Where condition1
        And condition 2
        &condition3 

1 个答案:

答案 0 :(得分:0)

您可能希望使用%SYSFUNC宏语句。

%sysfunc(tranwrd(&condition3,t1,t6))

您可以直接使用它,即不将其分配给另一个宏变量。您在PROC SQL中使用它的事实是无关紧要的,因为您只是创建要传递给(任何)的文本。

那就是说,你可能想考虑在这里使用宏而不是宏变量;如果它是

,这将更合乎逻辑
%macro condition3(table=);
  and &table..store in ('1234')
%mend condition3;

然后你可以在SQL中使用宏,就像宏变量一样。

where condition1
  and condition2
  %condition3(table=t6)