BookmarkSubscribeRSS Feed
abcd123
Fluorite | Level 6

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.

7 REPLIES 7
Cynthia_sas
SAS Super FREQ


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

abcd123
Fluorite | Level 6

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

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

Astounding
PROC Star

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.

abcd123
Fluorite | Level 6

Thank you all for help!

Amir
PROC Star

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.

ping
Fluorite | Level 6

you may try options nonotes nosource2;  to suppress annoying information

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 2393 views
  • 1 like
  • 6 in conversation