Macro programs Flashcards
Define a macro program with positional parameters.
Define a macro program with keyword parameters.
When mixing positional and keyword parameters, which one goes first?
Mix: positional parameters go before keyword parameters
%macro macro-name(parameter1, parameter2);
stuff
%mend (macro-name);
%macro macro-name(parameter1=value1, parameter2=value2);
stuff
%mend (macro-name);
Which option can you use to create a note in the SAS log when a macro has completed compilation?
OPTIONS MCOMPILENOTE = options;
options:
NONE: default. no message
NOAUTOCALL: note is made except for autocall macros
ALL: note is made for all completed macro compilations
How do you call a macro?
Where can you make a macro call within the program?
Does it require a semicolon?
%macroname
Can call a macro anywhere in a program except in DATALINES
Does NOT require a semicolon because it is not a SAS statement.
A macro call is processed by the macro processor before any ___ _____ ______ such as DATA steps are compiled or executed
A macro call is processed by the macro processor before any SAS language statements such as DATA steps are compiled or executed
When you call a macro, SAS language statements within the macro that are sent to the compiler do not appear in the SAS log. Which option can you use to see this text?
OPTIONS MPRINT;
Default is NOMPRINT
It writes to the SAS log each SAS statement generated by a macro.
How do you use MLOGIC? What does it do (5 things)?
OPTIONS MLOGIC;
Default is NOMLOGIC
It traces the flow of execution of your macro, including
- the beginning of macro execution
- the values of macro parameters at invocation
- the execution of each maccro program statement
- whether each %IF condition is true or false
- the end of macro execution
How can you place comments inside a macro definition?
Use macro comment statement:
%*comment;
or the good ol’
/*comment*/
How do you call a macro with keyword parameters?
%macroname(parameter1=value1, parameter2=value2)
How do you use the PARMBUFF option and what does it do?
%macro macroname/parmbuff;
text
%mend;
It allows you to create a macro that can accept a varying number of parameters. The list of parameters, including the parentheses, are stored in automatic macro variable syspbuff, so the text has to have a reference to it (%syspbuff).
How do you use the %GLOBAL statement and what does it do?
It can be used inside or outside macro definition.
It creates one or more macro variables in the global symbol table and assigns null values to them
e.g.
%global dsn vars;
How do you delete a macro variable from the global symbol table?
%SYMDEL macroname;
How can you create a global macro variable (4 ways)?
- %LET
- DATA step with SYMPUT
- SELECT statement with INTO clause in PROC SQL
- %GLOBAL
How do you create local macro variables (5 ways)
What special about the SYMPUT routine?
The SYMPUT routine can only create a local macro variable if a local symbol table already exists. If local symbol table doesn’t exist, SYMPUT creates a global macro variable
- parameters in a macro definiton
- %LET within a macro definition
- DATA step with SYMPUT within a macro definition
- SELECT statement with INTO clause in PROC SQL within a macro definition
- %LOCAL
%LOCAL
Where can you use it?
What does it do?
You can use it only inside a macro definition.
It creates one or more macro variables in the local symbol table and assigns null values to them
What steps does the macro processor go through when you use a %let statement within a macro program (eg. %let macvar=value)?
What if you use the %let statement in open code?
Note: same steps apply when you call a macro, e.g. &macvar
- The macro processor checks to see if macvar already exists in the local symbol table. If so, it updates macvar in the local symbol table with the value “value.” If macvar doesn’t exist in the local table, it goes on to step 2.
- The macro processor checks to see if macvar already exists in the global symbol table. If so, it updates macvar in the global symbol table with the value “value.” If macvar doesn’t exist in the global table, it goes to step 3.
- The macro processor creates a macro variable named macvar in the local symbol table and assigns a value of “value” to it.
If use %let in open code, the macro processor only checks the global symbol table.