Contact: chandanarasamadugu@gmail.com
Topics:
Introduction to Macros
How to Create & Subset Macros and Macro Variables
Macro Programming:
Macros can help in several ways:
• Automate the repetitive task
• Make our job easier by re-using similar code multiple times after defining it ones.
• Make changes in variable at a single place and reflect them at multiple locations.
• Make your programs data driven, letting SAS decide what to do based on actual
data values.
Components of Macro code:
Consists of two building blocks:
MACROS and MACRO VARIABLES.
MACRO VARIABLES:
• The names of macro variables start with an ampersand (&)
• A macro variable is like a standard data variable except that it does not belong to
a data set
• Has only a single value which is always character
• The value of a macro variable could be a variable name, a numeral, or any text you
want substituted in your program
• A macro variable can be referenced anywhere in a SAS program other than in
cards statement
Types of Macro variables:
%LET statement is used to create and assign value to macro variables.
Syntax: % LET Macro Variable Name=&Value;
Calling/ using the macro variable
Syntax: & Macro variable Name;
Local: “Local Macro variable” it is defined inside a macro. you can use a local
macro variable only inside its own macro.
Syntax: % LOCAL Macro Variable Name=&Value;
Macro-variable-name is a name you make up following the standard rules for SAS names
(32 characters or fewer in length; starting with a letter or underscore; and containing only
letters, numerals, or underscores).
Global: “Global Macro variable” it is defined in “open code” which is everything
outside a macro. You can use a global macro variable anywhere in your
program
Syntax: % GLOBAL Macro Variable Name=&Value;
Негізгі бет Macro Programming in SAS Day 1 | SAS MACROS
Пікірлер: 17