如何发现是否设置了 SAS 选项或 ODS 选项
How to discover if a SAS option or ODS option is set
我经常在 SAS 中编写通用宏。在我的宏中,我想应用一些设置,比如
- 宏变量
- SAS 选项
- ODS 选项
但之后我想"clean up my mess"。
对于将是
的宏变量
%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 选项不太确定..
我想您会在 this SAS help page 的 RESET= 和 Push 和 POP 部分中找到相关信息,其中遗憾的是仅适用于 ODS GRAPHICS 选项。
为了重置其他 ODS 设置,暴露了一种黑客攻击 here。
我经常在 SAS 中编写通用宏。在我的宏中,我想应用一些设置,比如
- 宏变量
- SAS 选项
- ODS 选项
但之后我想"clean up my mess"。
对于将是
的宏变量%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 选项不太确定..
我想您会在 this SAS help page 的 RESET= 和 Push 和 POP 部分中找到相关信息,其中遗憾的是仅适用于 ODS GRAPHICS 选项。
为了重置其他 ODS 设置,暴露了一种黑客攻击 here。