I'd like to share a nifty SAS option that will help tremendously with debugging SAS macros. The mprintNest system option will show nesting information in your log. This is a big improvement over mprint that showed which macro you were in, but made it nearly impossible to tell which macros may have contained the macro call.
With mprintNest you can see exactly where you are in the executing macro stack.
You must use mprintNest with mprint. It cannot be set on it's own.
Thursday, July 24, 2008
SAS Macro Nesting
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.
Wednesday, August 23, 2006
Options?
Here's something a little different. I have a colleague who asked if there was a way to save the current SAS options and then restore them somewhere in the middle of a job stream. Instead of keeping track of what linesize, pagesize, etc had been set to, he wanted to just reset everything back to some "base". I did not know a way to do that off the top of my head, but after a little poking around in the onLineDoc I thought I had found the answer:
proc optsave saves your current options to a data set or to a registry key.
proc optload loads and sets the options from a data set or registry key.
So at the beginning of your sas session you could have code like this:
proc optSave data = work.myOptions;
run;
And then anywhere in the code that you wanted to set the options back to the way they were when sas started you could run code like this:
proc optLoad data = work.myOptions;
run;
You would think that would do the trick, right?
Unfortunately it doesn't seem to work as advertised. My colleague wrote back with the following:
Try this code. I got inconsistant result:
options ls=100;
proc optsave out=work.ycOpt1;run;
%put ls is %sysfunc(getoption(LS));
options ls=120;
proc optload data=work.ycOpt1;run;
%put ls is %sysfunc(getoption(LS));
When it gets restored linesize (ls) is. . . 96!?
This is using SAS 9.13 on Windows XP. However, the exact same code works as expected under Unix and the linesize option gets correctly restored to 100.
What gives?