Friday, 11 March 2016

Debugging Complex Macros

It’s possible to write code generated by macros to an external file. The file can’t be access until the SAS session has ended. In SAS 6.12 you use the options RESERVEDB1 & MPRINT to achieve this. In version 8 you need to use the options MFILE & MPRINT. 

You then also need to define a fileref for MPRINT, to which the generated SAS code is written. 

filename mprint 'c:\macro.sas' ; 

This technique is very useful for complex macros with many loops and multiple ampersands since you can see the code that is generated. You can then run the code generated through data step debugger to resolve any problems or understand what is happening.

No comments:

Post a Comment