SAS如何根据条件制作sas代码

SAS how to make sas code on a condition-basis

我有这段代码

%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);

或者当然是在开放代码中。我想让条件只在数据步内工作,避免整个数据步重复。

只需删除不需要的并发症。此外,我假设您并不是要反转生成 WHERE 子句的逻辑。

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