Free macro for SAS developers:

announce your macro start in the log  

It is good programming practice to have your SAS macros announce their start and end in the log of your programs. Especially for standard macros and in software development this is very useful. It helps the user understand where the macro – and its submacros – start and end which aids in the debugging of programs. If you don’t already do this, we certainly recommend that you start doing it today. 

Such an announcement generally looks like this: 


Macro createfinalreport 


The following macro parameters were used: 



- TABNO    : 



The common approach to achieve this is to have each macro include a number of %put-statements that print the required lines in the log. 

%put =======================================================================; 

%put Macro createfinalreport; 

%put ------------------------------------------------------------------------; 

%put The following macro parameters were used:; 

%put - INDS     : %upcase(&inds.); 

%put - OUTTYPE  : %upcase(&outtype.); 

%put - TABNO    : %upcase(&tabno.); 

%put - PRINTDATE: %upcase(&printdate.); 

%put =======================================================================; 

While the result is perfect, the method is labour-intensive and prone to error. And wasn’t that what we were trying to avoid by making this macro after all? This code is going to be copied into new macros and someone is going to forget to change the macro name in the header. Or the macro is going to get changed with new parameters added, but no-one thinks of updating the %put-statements. The result is inconsistency which is going to lead to frustration and more work. 

Let’s look at a different approach. All the information required to put this – and more – into the log is already available to SAS. 

-   Copy and paste the code to a .sas file and store it in a folder that your SAS session can reach. 

-   In SAS, use %include or SASAUTOS to make the macro available. 

-   In your macro, add the %logPrintMacroStart call at or near the very beginning of your code. 

-   Run (i.e. compile) your macro and give it a go!