Printdsn
contains references
to the macro variables dsn
(which records
a data set name) and vars
(which records
a list of data set variables), as follows: %macro printdsn; proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %mend;
Printdsn
by changing the
value of macro variable dsn
or vars
with
a %LET statement before you call the macro. For example, you could
substitute sasuser.courses for dsn
and course_code
course_title days for vars
at macro execution,
as follows: %let dsn=sasuser.courses; %let vars=course_code course_title days; %printdsn
7 options mprint; 8 %let dsn=sasuser.courses; 9 %let vars=course_code course_title days; 10 %printdsn NOTE: Writing HTML Body file: sashtm.htm MPRINT(PRINTDSN): proc print data=sasuser.courses; MPRINT(PRINTDSN): var course_code course_title days; MPRINT(PRINTDSN): title "Listing of SASUSER.COURSES data set"; MPRINT(PRINTDSN): run; NOTE: There were 6 observations read from the data set SASUSER.COURSES. NOTE: PROCEDURE PRINT used (Total process time): real time 6.59 seconds cpu time 0.28 seconds |
dsn
to
sasuser.schedule and to change the value of vars
to
course_code location begin_date when the macro executes, as follows:
%let dsn=sasuser.schedule; %let vars=course_code location begin_date; %printdsn
11 %let dsn=sasuser.schedule; 12 %let vars=course_code location begin_date; 13 %printdsn MPRINT(PRINTDSN): proc print data=sasuser.schedule; MPRINT(PRINTDSN): var course_code location begin_date; MPRINT(PRINTDSN): title "Listing of SASUSER.SCHEDULE data set"; MPRINT(PRINTDSN): run; NOTE: Writing HTML Body file: sashtm1.htm NOTE: There were 18 observations read from the data set SASUSER.SCHEDULE. NOTE: PROCEDURE PRINT used (Total process time): real time 0.76 seconds cpu time 0.08 seconds |
General form, macro
definition that includes positional parameters:
%MACRO macro-name(parameter-1<,...,parameter-n>);
text
%MEND <macro-name>;
parameter-1<,...,parameter-n>
specifies one or more
positional parameters, separated by commas. You must supply each parameter
with a name: you cannot use a text expression to generate it.
|
dsn
and vars
in
the Printdsn
macro definition, as follows:
%macro printdsn(dsn,vars);
proc print data=&dsn;
var &vars;
title "Listing of %upcase(&dsn) data set";
run;
%mend;
Printdsn
macro you assign
values to the macro variables that are created in the parameters.
In the following example, the value sasuser.courses
is
assigned to the macro variable dsn
, and the
value course_code course_title days
is
assigned to the macro variable vars
. Notice
that the value for dsn
is listed first and
the value for vars
is listed second, since
this is the order in which they are listed in the macro definition.
%printdsn(sasuser.courses,course_code course_title days)
%printdsn(,course_code course_title days)
General form, macro
definition that includes keyword parameters:
%MACRO macro-name(keyword-1=<value-1><,...,keyword-n=<value-n>>);
text
%MEND <macro-name>;
keyword-1=<value-1><,...,keyword-n=<value-n>>
names one or more macro
parameters followed by equal signs. You can specify default values
after the equal signs. If you omit a default value, the keyword parameter
has a null value.
|
%macro-name(keyword-1=value-1<,...,keyword-n=value-n>)
dsn
and vars
in
the Printdsn
macro. This example assigns
a default value of sasuser.courses
to
the macro variable dsn
and assigns a default
value of course_code course_title days
to
the macro variable vars
: %macro printdsn(dsn=sasuser.courses, vars= course_code course_title days); proc print data=&dsn; var &vars; title "Listing of %upcase(&dsn) data set"; run; %mend;To invoke the
Printdsn
macro
with a value of sasuser.schedule
for dsn
and
a value of teacher course_title begin_date
for vars
,
issue the following call: %printdsn(dsn=sasuser.schedule, vars=teacher course_code begin_date)
Printdsn
macro
with default values for the parameters (sasuser.courses
as
the value for dsn
and course_code
course_title
days
as the value for vars
),
you could issue the following call: %printdsn()
Printdsn
with
default values for the parameters, you could also issue a macro call
that specified these values explicitly, as follows: %printdsn(dsn=sasuser.courses,vars=course_code course_title days)
General form, macro
definition that includes mixed parameters:
%MACRO macro-name(parameter-1<,...,parameter-n>,
keyword-1=<value-1><,...,keyword-n=<value-n>>);
text
%MEND;
parameter-1<,...,parameter-n>
is listed before keyword-1=<value-1><,...,keyword-n=<value-n>>.
|
%macro-name(value-1<,...,value-n>, keyword-1=value-1<,...,keyword-n=value-n>)
Printdsn
macro definition. This
code uses a positional parameter to create the macro variable dsn
,
and a keyword parameter to create the macro variable vars
:
%macro printdsn(dsn, vars=course_title course_code days);
proc print data=&dsn;
var &vars;
title "Listing of %upcase(&dsn) data set";
run;
%mend;
Printdsn
macro assigns the value sasuser.schedule
to
the macro variable dsn
and assigns the value teacher
location begin_date
to the macro variable vars
.
Notice that the value for dsn
is listed first,
since dsn
is the positional parameter. %printdsn(sasuser.schedule, vars=teacher location begin_date)
Printdsn
macro, assigning
the default value course_title course_code days
to
the macro variable vars
and assigning the
value sasuser.courses
to the macro
variable dsn
. You could issue the following
call: %printdsn(sasuser.courses)
vars
), the default
value for that parameter is used.
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 loop to print the data sets that are named as parameters.
%macro printz/parmbuff; %put Syspbuff contains: &syspbuff; %local num; %do num=1 %to %sysfunc(countw(&syspbuff)); %let dsname=%scan(&syspbuff,&num); proc print data=sasuser.&dsname; run; %end; %mend printz;
Printz
macro
writes the following line to the SAS log and causes two data sets
to be printed %printz(courses, schedule)
Printz
macro
writes the following line to the SAS log and causes one data set to
be printed: %printz(courses)