Google SAS Search

Add to Google

Thursday, September 07, 2006

Macro Debugging

Here's another SAS options related post. Have you ever had the frustration of debugging a big macro you didn't write? (Who hasn't!)

If you answered "yes" to the above then you probably know all about options MACROGEN and MPRINT. And you've probably spent a considerable amount of time staring at the log and all the messy MPRINT statements. Often the "bug" you are trying to find isn't necessarily in the macro code itself, but in the code it generates. Here's an easy way to get to that generated code so you can work directly with the logic it contains.

filename mprint "/tmp/code_to_debug.sas";
options mfile;

This will take the code generated by any subsequent macros and write it to the external file referenced by the filename statement.

2 comments:

  1. Very useful, but you also need to have
    the mprint option specified:

    options mprint mfile;

    SAS 9 docuementation on MFILE option:
    http://support.sas.com/onlinedoc/913/getDoc/en/mcrolref.hlp/a000209304.htm

    Dan Blanchette

    ReplyDelete
  2. That's a handy new feature, but if you're on V8 or earlier, or you can't rerun the macro to get the same log with different options, there's always my log analyser, Elvis.

    Interesting blog!

    ReplyDelete