1.

What do you mean by SAS Macros and why to use them?

Answer»

Macro is a group of SAS statements (program) that automates repetitive tasks. With SAS's Macros feature, we can avoid repeating SECTIONS of code and use them again and again when needed without having to type them again and it increases readability also. Automation makes your work faster because you don't have to write the same lines of code every day. %MACRO and %MEND are the start and end statements of a macro program. These can be reused multiple times. The SAS program declares them at the beginning and then calls them out during the body of the program when needed.

Macro variables contain a VALUE that will be used over and over again by SAS PROGRAMS. With a maximum of 65534 characters, macro variables are one of SAS's most powerful tools. They can be either global or local in scope. The % Local macro variable is a variable that can be defined and accessed inside macro programs only. The %Global macro variable is defined in OPEN code (outside of the macro program) and can be accessed from any SAS program running in the SAS environment. 

Syntax: The local variables are declared in the following syntax. 

In the following program, we have created the Macro variable in which we pass the parameters comma-separated and then we have written the Macro statement followed by the %MEND statement. After that, we have called the macro program by passing the parameters.

# Creating a Macro program. %MACRO <macro name>(Param1, Param2,....Paramn); Macro Statements; %MEND; # Calling a Macro program. %MacroName (Value1, Value2,.....Valuen);


Discussion

No Comment Found