MACRO STATEMENTS:
%Macro
Begins a macro definition or %macro creates a macro
Syntax: – %Macro Macro_Name(<Parameter1, Parameter2,…, ParameterN>)
%Mend
Ends a macro definition
Syntax: – %Mend;
%Macro_Name(Parameter1Value, Parameter2Value,…, ParameterNValue>)
Note:-If you specify a macro name with %Mend Statement that name should be match with %Macro Statement
It means both names should give same
Macro-name is a name you make up for your macro. The name must follow standard SAS naming conventions
(Start with a letter or underscore; contain only letters, numerals or underscores, and can be up to 32 characters in length).
The general form of Macro is (Creating Modular code with Macros)
Between %Macro and %Mend you can put any statements you want. The general form of a macro is
%Macro Macro_name;
Macro-Text
%Mend Macro_name;
The Modular approach to programming is good to avoiding Macro errors
First write standard SAS program and when it’s bug free convert it into Macro program
Adding one future at a time.
Invoking a macro
After you have defined a macro you can invoke it by adding the percent sign in front of Macro. Like below
%Macro_name
A semicolon is not required when invoking a macro, Generally if you add it doesn’t harm.
Example:-
%Macro Mac1;
Data ds;
Set sashelp.class;
Run;
Proc print data=ds;
Run;
%Mend;
%Mac1 ——- Invoking a Macro
%Put
Can used to write text (or) Macro variable information to SAS Log.
Syntax: – %put text
%put Macro_variable
Example:-
%put &Name.;
%put &Age.;
%put &Date.;
Prints all system defined macro variables in log.
%PUT _AUTOMATIC_;
Prints all global macro variables in log.
%PUT _GLOBAL_;
Prints all global and system defined macro variables in log.
%PUT _ALL_;
%PUT _USER_;
Prints macro variables that are created by the user in each environment.
%Include
Includes and executes SAS statements and data lines.
Syntax: – %Include source;
Example:- %include “D:\prg.sas”;
%include “D:\prg.txt”;