DATA Step, Macro, Functions and more

What is macro global debug variable

Reply
Super Contributor
Posts: 308

What is macro global debug variable

 

Dear

I need help in understanding about global debug variable. In our programming documentation it shows "include a global debug variable (‘analysis’ turns on resolved code generation)". I do not understand this statement.  Most of SAS code looks like below.

 

I am assuming the "debug " name is just used as a macro variable and &debug resolves to "N". Please suggest any documentation this. i searched  various macro debugging online documents did not see what i need. Thank you.

 

%let var_debug='N';

%macro adam(debug = &var_debug);
%if %qupcase(&debug)=%quote(ANALYSIS) %then %do;
%let _tpath=%sysfunc(pathname(tol));
filename mprint "&_path./adam_output.gen.sas" lrecl=2048;
%let rc=%sysfunc(fdelete(mprint));
options nomautolocdisplay mfile mprint;
%end;

"other sas statements"
%mend;

 

 

Super User
Posts: 22,873

Re: What is macro global debug variable

Posted in reply to knveraraju91

I believe this is a portion of code from a recent SAS post that illustrates how to debug your code with a debug option. 

 

See the full post here:

https://communities.sas.com/t5/SAS-Communities-Library/Include-Debugging-Code-in-Your-Programs/ta-p/...

 

This is a method/style of programming and as such wouldn't be documented. 

The functions and logical syntax is documented in the macro section. 

 

https://communities.sas.com/t5/SAS-Communities-Library/Include-Debugging-Code-in-Your-Programs/ta-p/...

Super User
Super User
Posts: 7,860

Re: What is macro global debug variable

[ Edited ]
Posted in reply to knveraraju91

Let's look at the example code you posted and see what it is doing.

%let var_debug='N';

This is setting the macro variable VAR_DEBUG to an uppercase letter n enclosed in single quotes.

%macro adam(debug = &var_debug);

This is beginning the definition of macro named ADAM that has one non-positional parameter named DEBUG whose default value (ie when the caller does not supply a value) that is value of the macro variable VAR_DEBUG.  To use this macro you should make sure to define the macro variable VAR_DEBUG before you call the macro ADAM.  Otherwise when the macro tries to reference the value of DEBUG you will get a warning in the SAS log like this:

WARNING: Apparent symbolic reference VAR_DEBUG not resolved.

Now this block of code in the macro is testing the value of the DEBUG parameter.

%if %qupcase(&debug)=%quote(ANALYSIS) %then %do; 
  %let _tpath=%sysfunc(pathname(tol)); 
  filename mprint "&_path./adam_output.gen.sas" lrecl=2048; 
  %let rc=%sysfunc(fdelete(mprint)); 
  options nomautolocdisplay mfile mprint; 
%end;

Only if the value of DEBUG is the word ANALYSIS (without regard to case of the letters) will it create the fileref and change the option settings.  It looks like the purpose is to turn on the MFILE option to direct the code that the macro generates to a file.

 

Note that there is no need to add the %quote() around the constant text ANALYSIS.

 

To prevent the warning if VAR_DEBUG has not been defined you could add this line before the %IF statement.

%if not %symexist(var_debug) %then %local var_debug ;
Ask a Question
Discussion stats
  • 2 replies
  • 111 views
  • 2 likes
  • 3 in conversation