我经常在SAS中编写通用宏。在我的宏中,我想应用一些设置,例如


宏变量
SAS选项
ODS选项


但是之后,我想“清理我的烂摊子”。

对于一个宏变量

%macro myMac();
    %let old_mac_var = &mac_var;

    %let mac_var = my_variable;
    %put Doing my stuf with &mac_var.;

    %let mac_var = &old_mac_var;
%mend;

%let mac_var = value before;
%myMac;
%put mac_var is &mac_var;


(当然,我会在实践中使用局部宏变量解决此问题,但这无关紧要。)

但是,对于其他设置我该怎么做呢?即如何完成此代码?

%macro test_mprint(should_shouldNot);
    data _null_;
        put "NOTE: 'data _null_;' &should_shouldNot. be readable here above in the log";
    run;
%mend;

%macro myMac();
    %let sas_mprint = ...;
    %let ods_exclude = ...;

    options nomprint;
    ods exclude none;

    title 'CARS should be printed because of ods option exclude none';
    proc print data=sashelp.class;
    run;
    %test_mprint(should not);

    options &sas_mprint.;
    ods exclude &ods_exclude.;
%mend;

options mprint;
ods exclude all;
%myMac;

title 'printing CLASS should be avoided by ods option exclude all';
proc print data=sashelp.class;
run;
%test_mprint(should);

最佳答案

SAS选项易于检索:

%let sas_mprint = %sysfunc(getoption(mprint));  /* gives, eg, NOMPRINT */


ODS选项不是很确定。

08-04 23:58