Select the best answer
for each question. After completing the quiz, check your answers using
the answer key in the appendix.
-
Which of the following
is false?
-
A %MACRO statement must
always be paired with a %MEND statement.
-
A macro definition can
include macro variable references, but it cannot include SAS language
statements.
-
Only macro language
statements are checked for syntax errors when the macro is compiled.
-
Compiled macros are
stored in a temporary SAS catalog by default.
-
Which of the following
examples correctly defines a macro named
Print
that
implements parameters named
vars
and
total
?
-
%macro print(vars, total);
proc print data=classes;
var vars;
sum total;
run;
%mend print;
-
%macro print('vars', 'total'),
proc print data=classes;
var &vars;
sum &total;
run;
%mend print;
-
%macro print(vars, total);
proc print data=classes;
var &vars;
sum &total;
run;
%mend print;
-
%macro print(vars, total);
proc print data=classes;
var :vars;
sum :total;
run;
%mend print;
-
Which of the following
correctly references the macro named
Printdsn
as
shown here:
%macro printdsn(dsn,vars);
%if &vars= %then %do;
proc print data=&dsn;
title "Full Listing of %upcase(&dsn) data set";
run;
%end;
%else %do;
proc print data=&dsn;
var &vars;
title "Listing of %upcase(&dsn) data set";
run;
%end;
%mend;
-
%printdsn(sasuser.courses, course_title days);
-
%printdsn(dsn=sasuser.courses, vars=course_title days)
-
%printdsn(sasuser.courses, course_title days)
-
%printdsn(sasuser.courses, course_title, days)
-
If you use a mixed parameter
list in your macro program definition, which of the following is false?
-
You must list positional
parameters before any keyword parameters.
-
Values for both positional
and keyword parameters are stored in a local symbol table.
-
Default values for keyword
parameters are the values that are assigned in the macro definition,
whereas positional parameters have a default value of null.
-
You can assign a null
value to a keyword parameter in a call to the macro by omitting the
parameter from the call.
-
Which of the following
is false?
-
A macro program is compiled
when you submit the macro definition.
-
A macro program is executed
when you call it (
%macro-name
).
-
A macro program is stored
in a SAS catalog entry only after it is executed.
-
A macro program is available
for execution throughout the SAS session in which it is compiled.
-
When you use an %IF-%THEN
statement in your macro program,
-
you must place %DO and
%END statements around code that describes the conditional action,
if that code contains multiple statements.
-
the %ELSE statement
is optional.
-
you cannot refer to
DATA step variables in the logical expression of the %IF statement.
-
-
Which of the following
can be placed onto the input stack?
-
-
only whole steps or
whole statements.
-
only whole statements
or pieces of text within a statement.
-
whole steps, whole statements,
or pieces of text within statements.
-
Which of the following
creates a macro variable named
class
in a
local symbol table?
-
data _null_;
set sasuser.courses;
%let class=course_title;
run;
-
data _null_;
set sasuser.courses;
call symput('class', course_title);
run;
-
%macro sample(dsn);
%local class;
%let class=course_title;
data_null_;
set &dsn;
run;
%mend;
-
%global class;
%macro sample(dsn);
%let class=course_title;
data _null_;
set &dsn;
run;
%mend;
-
Which of the following
examples correctly defines the macro program
Hex?
-
%macro hex(start=1, stop=10, incr=1);
%local i;
data _null_;
%do i=&start to &stop by &incr;
value=&i;
put "Hexadecimal form of &i is " value hex6.;
%end;
run;
%mend hex;
-
%macro hex(start=1, stop=10, incr=1);
%local i;
data _null_;
%do i=&start %to &stop %by &incr;
value=&i;
put "Hexadecimal form of &i is " value hex6.;
%end;
run;
%mend hex;
-
%macro hex(start=1, stop=10, incr=1);
%local i;
data _null_;
%do i=&start to &stop by &incr;
value=&i;
put "Hexadecimal form of &i is " value hex6.;
run;
%mend hex;
-
%macro hex(start=1, stop=10, incr=1);
%local i;
data _null_;
%do i=&start to &stop by &incr;
value=&i;
put "Hexadecimal form of &i is " value hex6.;
%end
run;
%mend hex;
-
When you submit a call
to a compiled macro, what happens?
-
First, the macro processor
checks all macro programming statements in the macro for syntax errors.
Then the macro processor
executes all statements in the macro.
-
The macro processor
executes compiled macro programming statements.
Then any SAS programming
language statements are executed by the macro processor.
-
First, all compiled
macro programming statements are executed by the macro processor.
After all macro statements
have been processed, any SAS language statements are passed back to
the input stack in order to be passed to the compiler and then executed.
-
The macro processor
executes compiled macro statements.
If any SAS language
statements are encountered, they are passed back to the input stack.
The macro processor
pauses while those statements are passed to the compiler and then
executed.
Then the macro processor
continues to repeat these steps until it reaches the %MEND statement.