Transcript macro2.ppt

Basics of Macros
You must be disciplined to code with
macros
How SAS processes code
code
Triggered by & or %
Word
Scanner
Compiler
Macro
Processor
Execution of Data
Steps and Procs
Symbol
Table
Writing a macro – three steps
We would only use a macro when we
have several similar tasks to perform
A) First code without macros – clean, clear code
B) Recode with substitution macro variables:
%let macvar=testcase ;
C) Repackage as macro
Key macro tools
• Macro level assignment of macro variable:
%let macrovar = charvalue ;
• Data step assignment of macro variable
call symput(‘macrovar’,number) ;
number converts to character; symputx trims
• (Dynamic) use of macro variable in Data step
variable = symget(‘macrovar’) ;
• Evaluation of character expression: %eval