我可以有条件地将语句打印到外部 SAS 程序文件吗?

Can I conditionally print statements to an external SAS program file?

我有以下代码,我正在尝试从宏生成独立代码(写入外部 sas 文件)。但是,默认情况下会生成完整代码并将其写入外部文件。我想知道是否有一种方法可以控制将宏的哪些部分写入外部文件。感谢我在此方面获得的所有帮助。

%macro tempmacro(outds=);

/* I dont want this following code to be printed */
    proc sql noprint;
        SELECT cats(name,"=",substr(name,2))
        INTO :renames SEPARATED BY " "
        FROM dictionary.columns
        WHERE LIBNAME="SASHELP" AND MEMNAME=upcase('BASEBALL');
    quit;

/* I only Want this following data step printed to the external file */
data &outds;
set sashelp.baseball;
rename &renames;
run;

%mend;


options mfile mprint;
filename mprint "D:\test_code.sas";
data _null_;
file mprint;
%tempmacro(outds=data1);
options nomfile nomprint;
run;

proc sql 之前设置 option nomprint,然后在 option mprint 之后恢复它。对于奖励 UX 点,请在宏的开头使用 %sysfunc(getoption(mprint)) 之前检查选项的值,然后将其恢复为相同的值。