Introduction to Macros :
Macro is a stored text that can be set anywhere in SAS Program and expanded.
(Or)
Macro is a stored code that can be used repeatedly with the macro name.
Uses of SAS/Macros
–> Reduce the amount of programming needed for repeated tasks
Example:-
When we have to extract 10 Excel files from external location to SAS We need to write
10 times Proc import statements but using Macros we can write in single step.
%macro import(file,dname);
Proc import datafile=”&file” out=&dname
Dbms=excel replace;
Getnames=yes;
Run;
%mend;
%import(E:\sas\macro\data1.xls,ds1);
%import(E:\sas\macro\data2.xls,ds2);
%import(E:\sas\macro\data3.xls,ds3);
%import(E:\sas\macro\data4.xls,ds4);
%import(E:\sas\macro\data5.xls,ds5);
%import(E:\sas\macro\data6.xls,ds6);
%import(E:\sas\macro\data7.xls,ds7);
%import(E:\sas\macro\data8.xls,ds8);
%import(E:\sas\macro\data9.xls,ds9);
%import(E:\sas\macro\data10.xls,ds10);
-> Minimize on typing and execution errors
-> Making the variables global
-> Simplifying the code
-> In Macros we have only one data type that is character.
Generally Macro code takes longer time to write and debug than standard SAS code, But if you find yourself writing similar code over and over again then macros may make your job easier.
THE MACRO PROCESSOR
The most important concept to keep in mind whenever you write macro code is that
You are writing a program that writes a program.
Here is how it works.

When you submit a standard SAS program, SAS compiles and then immediately executes it. But when you write macro code, there is an extra step. Before SAS can compile and execute your program, SAS must pass your macro statements to the macro processor which then “resolves” your macros generating standard SAS code. Because you are writing a program that writes a program, this is sometimes called meta-programming.
TURNING ON MACRO PROCESSOR
Before you can use macros you must have check Macro system is turned on or not, this option is turned on by default, may be its turned off by some times, to find out whether it’s on or off execute below program lines
Proc options option=macro;
Run;
See the log
If you see the option MACRO then macro processor is turned on
If you see the option NOMACRO then macro processor is turned off
3 Proc options option=macro;
4 Run;
SAS (r) Proprietary Software Release 9.2 TS2M2
MACRO Allow use of SAS macro facility
NOTE: PROCEDURE OPTIONS used (Total process time):
real time 0.00 seconds
cpu time 0.00 seconds