11-07-2016 07:43 AM - edited 11-07-2016 07:48 AM
The macro language is a pre-processor that allows one to create program code dynamically, equally to the function of the C preprocessor.
Macro statements are acted upon immediately when encountered, the resulting code is then fed on to the regular SAS interpreter for running (procedures) or compiling and executing (data step).
11-07-2016 07:49 AM
The most comprehensive source for information is the SAS documentation itself, a good starting point for the macro language is here: https://support.sas.com/documentation/cdl/en/mcrolref/67912/HTML/default/viewer.htm#p1ccprwibo8gvqn1...
11-07-2016 08:13 AM
There is a ton of material on the macro language in SAS, a quick google search will get you far.
This is eg a good starting point with a low of simple examples along with a few videos with explanation.
11-07-2016 08:53 AM - edited 11-07-2016 09:05 AM
Generally speaking from 99% of the examples I have seen it is to obfuscate and complicate code. SAS Base (also known as dataste) is the programming language - this should be the main part to learn and will cover 99% of all encountered needs. It contains all the data structures, functions and such like to manipulate and process data.
Macro language is an additional tool, used to generate Base SAS code. It does nothing on its own other than generate text. It has no data structures other than text, and it has no procedures/functions other than a couple of basic ones to generate text.
If you do need to write macro code - maybe for libraries or general code - then you should really be following Software Development Lifecycle mehodology - design the code in a documen first, create a teting plan, create a management plan etc. Then write some code. Don't fall into the "have to" use macro code, or over using it - Base SAS is where you can do almost every task imaginable.
I would also add, in the large majority of cases where macro is used, it is necessary for one of two reasons:
- Poor data structuring, some examples of which - holding similar data in many different datasets, using data as dataset names/variable names, using wide rather than long format (i.e. using a review type layout, rather than one designed for programming)
- Lack of understanding of Base SAS, something like using macro to loop over variables when arrays can do that, or generating lots of proc print/report statements rather than using by group processing.