How can I get information to debug my SAS macro?

Two SAS system options are very helpful in debugging macro programs. They are mprint and mlogic.

Let's take a look at an example. In the macro program below, a data set with a given name and a given number of observations is generated.

%macro test(num, data);
  data &data;
    do i = 1 to #
	  x = ranuni(-1);
  proc means data = &data;
    var x;

How do we know what is happening when we run this macro program? Let's turn on the option of mprint and mlogic and run the program.

options mprint mlogic;
%test(10, test);

In the log window, we will see the following.

1246  options mprint mlogic;
1247  %test(10, test);
MLOGIC(TEST):  Beginning execution.
MLOGIC(TEST):  Parameter NUM has value 10
MLOGIC(TEST):  Parameter DATA has value test
MPRINT(TEST):   data test;
MPRINT(TEST):   do i = 1 to 10;
MPRINT(TEST):   x = ranuni(-1);
MPRINT(TEST):   output;
MPRINT(TEST):   end;
MPRINT(TEST):   run;
MPRINT(TEST):   proc means data = test;
MPRINT(TEST):   var x;
MPRINT(TEST):   run;
MLOGIC(TEST):  Ending execution.

As shown above, option mlogic tells us the parameter values and option mprint translates the macro language to regular SAS language.

How to cite this page

Report an error on this page or leave a comment

The content of this web site should not be construed as an endorsement of any particular web site, book, or software product by the University of California.