0

下面的代码 1 根据用户提示输入在 Proc SQL 中创建 where 子句('Str' 表示商店编号)我想使用宏(参见下面的示例代码 2)来替换宏变量。请问我怎样才能让它工作?谢谢!

代码 1

%global STR_COUNT STR;
%let STR_WHERE_CLAUSE=;
data _null_;
if missing(symget('str'))=0 then
do;
length STR_LIST $1000; 
STR1=symget('STR');
STR2=put(input(STR1,best4.),z4.);
STR_LIST=quote(STR2);
put STR_LIST;
end;
if missing(STR_LIST)=0 then
call symputx('STR_WHERE_CLAUSE',cats(' and T1.STR_SITE_NUM in (',STR_LIST,')'));
run;
%PUT &STR_Where_Clause;

代码 2

%macro condition3(table=);
and &table..store in ('1234')
%mend condition3;

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

select xxx from t1, t2 where condition1
and condition2
%condition3(table=t6)
4

1 回答 1

0

我不确定我是否完全理解你的问题。但是,如果您尝试将代码 1 包装在宏中并用宏函数替换 datastep 逻辑,这应该可以帮助您:

%macro condition3(table, STR);
    %let STR_LIST = %sysfunc(putn(STR, z4.));
    and &table..store in ("&STR_LIST.")
%mend condition3;

proc sql;
    select xxx 
    from 
        t1, 
        t2 
    where 
        condition1 and
        condition2
        %condition3(t6, 34);
quit;   
于 2014-09-18T17:45:10.040 回答