SAS programmers use Macros in SAS to save their time since one programming code to make a small change in the program can execute that change throughout all the programs. Macros allow programmers to write a piece of code once and use it over and over again (in the same program or in different programs). Macros that are generated can also be stored in an auto call library. These macros can be shared between programs and also between programmers. Macro programs can do repetitive tasks such as creating or analyzing a series of data sets. SAS macro code consists of two basic parts: macros and macro variables. The names of macros are prefixed with a percentile sign (%) and the names of macro variables are prefixed with an ampersand sign (&). A macro variable has only a single value and does not belong to a data set. Its value is always character. This value could be a variable name, a numeral, or any text that the programmers want to substitute into the programs. A macro can also be a larger piece of a program that may contain complex logic including complete DATA step and PROC steps and macro statements such as %DO, %THEN and %IF-%THEN/%ELSE. Macro variables have two kinds of scope---local or global. A macro variable is local if it is defined inside a macro. A macro variable is generally global if it is defined outside a macro. A global macro variable can be used anywhere in the program, but a local macro variable can only be used inside its own macro. In general these macros developed in SAS software are very flexible for repeated use and can work with varying needs of report presentation. Post processor macros generally take care of different formatting, display and other presentation attributes associated with the report. When a normal dataset is written in SAS and submitted for execution in the SAS environment it passes through a process in the backend of SAS software, Data steps or proc steps are passed through the a process like. Input stack – used to hold a SAS program after it is submitted and before it is processed by the word scanner. Word scanner- Scans the text it takes from the input stack and breaks the text into different tokens (Tokens are the fundamental unit in the SAS language), where it determines the destination of the token: DATA step compiler, proc step compiler, macro processor, etc. Compiler- Checks the syntax of tokens received from the word scanner. After it completes checking the syntax, the compiler translates the tokens into a form for execution. If the dataset has some Macro triggers, then these triggers will be sent to Macro processing unit. Macro processor- Processes macro language references and statements used in a data step, where macro triggers like & and %, which signals the word scanner to transfer what follows to the macro symbol table. Macro symbol table - The area in memory where macro variables and their associated values are stored and referenced to trigger a macro value. The advantage of Macro Programming is: The SAS programming productivity can be improved when the programmer knows how and when to use the SAS macro facility. The programs written can become reusable, shorter and easier to follow. In addition, by incorporating macro facility features in SAS programs one can: • Accomplish repetitive tasks quickly and efficiently. • A macro program can be reused many times. • Parameters passed to the macro program customize the results without having to change the code within the macro program. • Provide a more modular structure to SAS programs. • SAS language that is repetitive can be generated by macro language statements using macro programs. Conclusion: The macro facility is a tool for extending and customizing SAS and for reducing the amount of text that have to be entered to do common tasks. The macro facility enables the programmers to assign a name to character strings or groups of SAS programming statements or conditions. Rather than working with text data or group of programming statements directly, programmers can create a macro variable name in which the text values or programming statements or conditions are saved. These macro variables can be reused in different programming statements for execution. Clinnovo is a clinical innovation company. It is pioneer CRO industry in India. Clinnovo offers professional clinical research course , clinical data management course , SAS Course and imaging training. Clinnovo has been serving different bio-pharma industries across the world with excellence and high quality. For more information contact at +91 9912868928, 040 64635501
Related Articles -
SAS, Macros, datasets, prorams, Analysis, Data, Clinical Data, Clinical Research, Data Management, Statistics, Macro Programs, Reports, Codes, execute,
|