Help using Base SAS procedures

how to debug SAS macro

Reply
Contributor
Posts: 51

how to debug SAS macro

Hello,

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.

SAS Super FREQ
Posts: 8,743

Re: how to debug SAS macro


Hi:

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

cynthia

Contributor
Posts: 51

Re: how to debug SAS macro

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

Super User
Super User
Posts: 6,499

Re: how to debug SAS macro

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.

Super User
Posts: 5,081

Re: how to debug SAS macro

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:

endsas;

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.

Contributor
Posts: 51

Re: how to debug SAS macro

Thank you all for help!

Super Contributor
Posts: 282

Re: how to debug SAS macro

Hi,

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

Regards,

Amir.

Contributor
Posts: 22

Re: how to debug SAS macro

you may try options nonotes nosource2;  to suppress annoying information

Ask a Question
Discussion stats
  • 7 replies
  • 426 views
  • 1 like
  • 6 in conversation