12-16-2013 11:31 AM
I have a very long SAS macro (thousands of lines)to debug. For example
%let count =&sqlobs;
I would like to pause the program while it was running and see what is the value of count; I know in other computer language there is usually such a debug facility to do this. Is there a similar tool in SAS? Or do I have to scroll down the log file (which could be tens of thousands of lines) to search for the value? Thanks.
12-16-2013 11:53 AM
If you use the SAS Windowing environment, you can use the DATA Step debugger to debug a DATA step program. However, there is no equivalent for a SAS Macro program. Generally, the way to NOT have to debug a macro program is to start with an error-free SAS program that does what you want to do, produces the output you want and then you "macro-ize" that program. But, some statements, such as the %LET statement get resolved at code compile time, versus code execution time, so that is one challenge, I often use a lot of %PUT statements to help figure out what's going on. Also using the MPRINT MLOGIC and SYMBOLGEN options are a great help in debugging and showing you how macro variables have resolved. There have been quite a few user group papers written about how to write a program to read the log file to summarize errors, warnings, etc, however, that is not an interactive debugging technique and doesn't have much over just using the editor's search functionality (for me).
12-16-2013 12:34 PM
You could use %WINDOW/%DISPLAY to pop-up a window. This will let you do some things while it waits for you to respond the the displayed windows. but you will be very limited in what you can do while this window is running
Note that you would need to write that into the macro, the same as any other debugging code that you want to insert.
12-16-2013 02:29 PM
You can always display the value of a macro variable:
%put COUNT is &count..;
In fact, it's just as easy to see the values of all user-defined macro variables:
It's also easy to add an easy-to-locate diagnostic, such as:
%put *** HERE IT IS !!! ***;
%put COUNT is &count..;
And it's also easy to just halt the program after the %PUT statements by adding:
Just note that ENDSAS will stop your entire SAS session, so:
(a) Don't use it when using SAS interactively, and
(b) Don't expect to resume the program afterwards.
12-17-2013 07:19 AM
If it is of any help, I have used the SAS data step debugger on data step code generated by macros as described in the last section of:
and if you need an introduction to the data step debugger then see: