Macro Debugging

Reply
Occasional Contributor
Posts: 15

Macro Debugging

[ Edited ]

I want to know how should I exactly point out the error location in an included sas macro.

 

e.g. If I am calling an included macro the log only tells me that error occured at the line where I call the macro. I have no information about where to serarch inside that huge included macro.

 

ex. the log looks like below.

 

%include "/abc/getMyOutput.sas";

 

5%getMyOutput();

6

7

 

NOTE: Division by zero detected at line 5 column x.

WARNING: Limit set by ERRORS= option reached.  Further errors of this type will not be printed.
RULE:     ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8----+----9----+----0

 

Any idea how I can see where inside that macro real problem occurs.

 

Thanks for your time.

 

 

See below code example.

 

data y;

c=5;

run;

%include "./include.sas";

%getit;

 

 

 

 

%macro getit;

 

data x;

set y;

a=5;

b=c/0;

 

run;

%mend getit;

 

Super User
Posts: 21,481

Re: Macro Debugging

options mprint symbolgen;

Set the options above and you'll get the code in your log and you should be able to track the issue.

PROC Star
Posts: 7,787

Re: Macro Debugging

In addition to the two options that @Reeza recommended, I'd also include the mlogic option.

 

Art, CEO, AnalystFinder.com

 

Occasional Contributor
Posts: 15

Re: Macro Debugging

I added all the options but it still does the same thing. see below.

 

1 options symbolgen mlogic mprint;

2

3 data y;

4 c=5;

5 run;

 

NOTE: The data set WORK.Y has 1 observations and 1 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.02 seconds

 

 

6 %include "/include.sas";

18 %getit;

MLOGIC(GETIT): Beginning execution.

MPRINT(GETIT): data x;

MPRINT(GETIT): set y;

MPRINT(GETIT): a=5;

MPRINT(GETIT): b=c/0;

MPRINT(GETIT): run;

 

NOTE: Division by zero detected at line 18 column 26.

2 The SAS System 16:19 Wednesday, August 30, 2017

 

WARNING: Limit set by ERRORS= option reached. Further errors of this type will not be printed.

c=5 a=5 b=. _ERROR_=1 _N_=1

NOTE: Mathematical operations could not be performed at the following places. The results of the operations have been set to

missing values.

Each place is given by: (Number of times) at (Line)Smiley SadColumn).

1 at 18:26

NOTE: There were 1 observations read from the data set WORK.Y.

NOTE: The data set WORK.X has 1 observations and 3 variables.

NOTE: DATA statement used (Total process time):

real time 0.00 seconds

cpu time 0.00 seconds

  

MLOGIC(GETIT): Ending execution.

 

See above the place is given by line 18: column 26

Now if you see above line 18 is the macro call. So it does not say inside the macro where exactly the error occurs.

 

 

Super User
Posts: 21,481

Re: Macro Debugging

Add SOURCE2 to your %INCLUDE statement as well.

 

Note that the error does tellyou the data set so hopefully that should allow you to see the section of code that needs fixing.

 

NOTE: There were 1 observations read from the data set WORK.Y.

NOTE: The data set WORK.X has 1 observations and 3 variables.

 

Occasional Contributor
Posts: 15

Re: Macro Debugging

Yes, but what if you have hundreds of calculation in that data step. If it points me to a specific line then it is very easy.

Super User
Posts: 12,148

Re: Macro Debugging

And turn of the options after you get things fixed:

 

options nomprint nosymbolgen nomlogic;

Ask a Question
Discussion stats
  • 6 replies
  • 133 views
  • 0 likes
  • 4 in conversation