If you’ve been writing the same line of codes and repeat in SAS, you can stops now. It shouldn’t be as laborious as you’ve been. Available of SAS Macros can makes you work faster and saves your day. I’ve work on SAS. I remember writing same line of codes and every morning. Since then, persist to learning every bits of techniques to makes coding faster in SAS.Here is a complete tutorials on using SAS Macros. It will helps you to becomes better and more faster in SAS programming.
SAS macros enable us to:-
Make our jobs and easier to by re-using similar code multiple times after defining it one.
Make change in variables at a single places and reflects them at multiple location.
Make your program data driven, i.e. letting SAS decides what to do based on actual data value.
Above all, it helps to reduce the efforts required to read and write SAS Code. Macro programming is typically covered as advanced topic in SAS, but the basic concepts of SAS macros are easy to understand.
I will now introduce the concept of SAS programming and I assume that you are aware about basics of SAS programming. We will looking at how macros as processor work, how to uses the SAS macros & macro variable and How to creates the flexible and reusable codes to save time and effort.
How does Macro Processor Works?
A SAS programming is a combination of Data step, global statement, SAS Components and Language (SCL), SQL statement and SAS Macros statement. Whenever we submit a programs, it get copied in memories (called input stacks) followed by word scanner and there after it goes to compilers and gets executed. When we uses the Macros in our SAS programs, an additional steps is added to resolve macro. This steps is called as MACRO Processors.
What are the component of Macro codes?
Macro code consist of two basic building block: Macros and Macro variable. In a SAS programs they are referred different as:-
- & Name refer to Macro Variable
- %Name refer to Macro
What are Macro Variables ?
A macro variable is just like a standard variable, except that its value is not a data set and has only a single character value. The value of a macro variable could be a variable name, a numeral, or any text you want substituted in your program.
Scope of Macro variable can be local or global, Add Media depending on how we have defined it. If it is defined inside a macro program, then scope is local (only available for that macro code). However, if we have defined it outside (in the main body), then we can use it anywhere in SAS program.
- %LET statements is used to creates and assign the values to macro variable.
Macro variables name follow the SAS naming conventions and if variable already exist then values is overwritten.
Value of macro variable in %Let statements can be any strings and it has following characteristic
- It can be of any length between 0 to 65,534 character
- Numeric value are also stored as character strings
- Mathematical expression are not evaluated
- Quotation marks can also be stored as a parts of value
- Leading and trailing blanks are removed before assignments
Macro variable are reference by using ampersand (&) followed by macro variables and name.
Our Other Top Courses :