Macros That Include the PARMBUFF Option
You can use the PARMBUFF option in a macro definition to create a macro that can accept a varying number of parameters at each invocation. The PARMBUFF option assigns the entire list of parameter values in a macro call, including the parentheses in a name-style invocation, as the value of the automatic macro variable SYSPBUFF.
|
General form, macro definition with the PARMBUFF option:
%MACRO macro-name /PARMBUFF;
text
%MEND;
where text contains a reference to the automatic macro variable SYSPBUFF.
|
The following macro definition creates a macro named Printz. Printz uses a varying number of parameters and the automatic macro variable SYSPBUFF to display the parameters that are specified in the macro call. The macro also uses a conditional loop to print the data sets that are named as parameters, and the %EVAL function to increment the macro variable num. You will learn more about the %EVAL function later in this lesson.
%macro printz/parmbuff;
%put Syspbuff contains: &syspbuff;
%let num=1;
%let dsname=%scan(&syspbuff,&num);
%do %while(&dsname ne);
proc print data=sasuser.&dsname;
run;
%let num=%eval(&num+1);
%let dsname=%scan(&syspbuff,&num);
%end;
%mend printz;
If you submit a call to the macro that includes two parameters, the Printz macro writes the following line to the SAS log and causes two data sets to be printed:
%printz(courses, schedule)
SAS Log
If you submit a call to the macro that includes one parameter, the Printz macro writes the following line to the SAS log and causes one data set to be printed:
%printz(courses)
SAS Log
|
No comments:
Post a Comment