BookmarkSubscribeRSS Feed
Fluorite | Level 6


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.



  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).


Fluorite | Level 6

Thanks. so, there is no way to pause a macro, right?

Super User Tom
Super User

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.


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:

%put _user_;

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.

Good luck.

Fluorite | Level 6

Thank you all for help!



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:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition

and if you need an introduction to the data step debugger then see:

SAS(R) 9.2 Language Reference: Dictionary, Fourth Edition



Fluorite | Level 6

you may try options nonotes nosource2;  to suppress annoying information


Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.


Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 7 replies
  • 1 like
  • 6 in conversation