【问题标题】:SAS how to make sas code on a condition-basisSAS如何根据条件制作sas代码
【发布时间】:2021-04-22 09:57:53
【问题描述】:

我有这段代码

%macro test(full);

%if &full. = 0 %then %do;
data temp;
set sashelp.air;
run;
%end;

%if &full. = 1 %then %do;
data temp;
set sashelp.air;
where air > 140;
run;
%end;

%mend;

%test(1);

或在开放代码中

%let full = 1;

%if &full. = 0 %then %do;
data temp;
set sashelp.air;
run;
%end;

%if &full. = 1 %then %do;
data temp;
set sashelp.air;
where air > 140;
run;
%end;

有没有办法得到类似的东西(这段代码不起作用):

%macro test(full);

data temp;
set sashelp.air;
%if &full. = 0 %then %do; %sysfunc(call execute('where air>140;'));    %end;
run;
%mend;

%test(1);

当然也可以是开放代码。我想让条件只在数据步内起作用,避免整个数据步重复。

【问题讨论】:

    标签: sas sas-macro


    【解决方案1】:

    只需消除不必要的并发症。另外我假设您并不是要颠倒生成 WHERE 子句的逻辑。

    data temp;
      set sashelp.air;
    %if &full.=1 %then %do; 
      where air>140;
    %end;
    run;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-11
      相关资源
      最近更新 更多