BookmarkSubscribeRSS Feed
knveraraju91
Barite | Level 11

 

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;

 

 

2 REPLIES 2
Reeza
Super User

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

Tom
Super User Tom
Super User

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 ;

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!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

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
  • 2 replies
  • 794 views
  • 2 likes
  • 3 in conversation