LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (July 2008, week 1)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Thu, 3 Jul 2008 02:09:06 +0000
Reply-To:     iw1junk@COMCAST.NET
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Ian Whitlock <iw1junk@COMCAST.NET>
Subject:      Re: Debug a macro code, locate where the NOTE is at?
Comments: cc: SUBSCRIBE SAS-L Dan <deniseyu001@GMAIL.COM>

Summary: Debugging Macro with MFILE #iw-value=2

In SAS version 5 or 6 they dropped trying to maintain line numbers in the log for the MPRINT option. The solution to getting line numbers is to use the MFILE option with MPRINT. In this case the mprint output ready to execute is written to a file with the fileref, MPRINT. The catch is that any code not generated by macro will be left out.

Let's look at a simple example.

%macro q ; data w ; length y $ 5 ; set w ; y = x ; run ; %mend q ;

data w ; x = 1 ; run ;

%q

The DATA step generated by %Q contains a conversion message so we can get that code into a file for execution but the creating DATA step will be missing. The simple solution is wrap everything in a macro.

%macro debug ;

%macro q ; data w ; length y $ 5 ; set w ; y = x ; run ; %mend q ;

data w ; x = 1 ; run ;

%q

%mend debug ;

(This is one case I generally overlook the crime of compiling a macro in a macro execution since it is only for the purpose of debugging.)

Now add

options mprint mfile ; filename mprint temp ; %look

%inc mprint /source2 ;

The code executes twice so you want to think about doing this with very large and expensive runs. The other problem is that the error in the first run, under %LOOK, may cause SAS to not execute the include file. In this case you need a permanent file and do the execution in a separate job. However, for this vexing problem of which line causes conversion, that is not the case.

The relevant log is

27 +data w ; 28 +length y $ 5 ; 29 +set w ; 30 +y = x ; 31 +run ;

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 30:5

So know we know the crime was committed by

y = x ;

at line number 30.

If one plans a program for testing of independent modules, this sort of thing can be very easy to do even with very large and complex programs.

If you need more it is described in "Macro Bugs - How to Create, Avoid and Destroy Them" at www2.sas.com/proceedings/sugi30/252-30.pdf

Ian Whitlock ================ Date: Wed, 2 Jul 2008 12:46:35 -0400 Reply-To: SUBSCRIBE SAS-L Dan <deniseyu001@GMAIL.COM> Sender: "SAS(r) Discussion" From: SUBSCRIBE SAS-L Dan <deniseyu001@GMAIL.COM> Subject: Debug a macro code, locate where the NOTE is at?

Hi. SaSlers:

I have a very complex macro code passed to me. I have something like this:

NOTE: Numeric values have been converted to character values at the places given by: (Line):(Column). 1086:13 1086:64 NOTE: Character values have been converted to numeric values at the places given by: (Line):(Column). 1086:6 1086:28

It seems that the log only has the line number ending on 574.

It is not my program. I am not sure what options would take out line number in LOG. I do not know what options to pin point the problematic place inside macro.

Thanks for your help.

Dan


Back to: Top of message | Previous page | Main SAS-L page