1

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

顺便说一句,&condition3决定:and t1.store in ('1234')

完整的查询:

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

1 回答 1

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)
于 2014-09-12T15:48:58.687 回答