BookmarkSubscribeRSS Feed
Anindita
Calcite | Level 5

what is the use of macro in sas?

6 REPLIES 6
PeterClemmensen
Tourmaline | Level 20

Do you mean how to run a macro? 🙂

 

Please be more specific

Anindita
Calcite | Level 5
yea, i want to know about the structure and the functions of macro..
Kurt_Bremser
Super User

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).

PeterClemmensen
Tourmaline | Level 20

There is a ton of material on the macro language in SAS, a quick google search will get you far.

 

http://www.ats.ucla.edu/stat/sas/seminars/sas_macros_introduction/

 

This is eg a good starting point with a low of simple examples along with a few videos with explanation. 

 

Good luck 🙂

RW9
Diamond | Level 26 RW9
Diamond | Level 26

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.

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 962 views
  • 5 likes
  • 4 in conversation