您將使用宏引用來完成此操作。
一個簡單版本的例子:
%macro outer_macro(macro);
%put Starting outer macro;
%unquote(¯o) /* %unquote removes the NRSTR escape characters */
%put Ending outer macro;
%mend outer_macro;
%macro inner_macro;
%put Starting inner macro;
proc print data=sashelp.class;
run;
%put Ending inner macro;
%mend inner_macro;
%outer_macro(%nrstr(%inner_macro)) /* %nrstr is execution-time quoting, so %inner_macro is passed and not treated as a macro until %unquote removes the quoting */
涉及到像一個循環,你只要確保一切都建立起來,可以將循環迭代 - 一個辦法就是追加()與循環。
%macro outer_macro(macro);
%put Starting outer macro;
%do i = 1 %to 19;
%unquote(¯o)(n=&i.) /* resolves to %inner_macro(n=&i.) */
%end;
%put Ending outer macro;
%mend outer_macro;
%macro inner_macro(n=);
%put Starting inner macro;
proc print data=sashelp.class(obs=&n. firstobs=&n.);
run;
%put Ending inner macro;
%mend inner_macro;
%outer_macro(%nrstr(%inner_macro))
來源
2017-06-22 15:53:14
Joe