Hello
What does it mean debug information?
In which situation we need to use this type of code ?
I will appreciate if anyone can explain it.
I saw the defintion of debugging "Debugging is the routine process of locating and removing computer program bugs, errors or abnormalities, which is methodically handled by software programmers viadebugging tools. Debugging checks, detects and corrects errors or bugs to allow proper program operation according to set specifications"
Thanks
Joe
/* Conditionally produce debugging information */
%let _DEBUG = 0; /* set to 1 for debugging */
%if &_DEBUG. %then
%do;
proc print data=sashelp.class(obs=10);
run;
%end;
Some of us programmers who are not as talented as you are ... we occasionally make mistakes. We might want additional information to help us figure out where the mistakes are and what to fix. In this case, that information is to print the first ten observations of a data set. But once the mistakes are fixed, we don't want to print those 10 observations any more. So in this example, the debugging information is the printing of 10 observations that we can turn on by setting &_DEBUG to 1, and turn off by setting &_DEBUG to 0.
Thank you.
Usually I turn off print by put it in notes (/************************/)
As I understand ,alternatively, I can change the value in %let _DEBUG from 0 to 1
%let _DEBUG = 0;
There are no builtin options in sas to debug a program.
You can find some system variables to be checked: &syserr, &sysrc and others.
Usually if you observe an error, either in log or in your output, you need to DEBUG your program
by adding specific code which should not run after all errors corrected.
you can use a flag to define whether to run your debugging code or not, like in your example,
or you can enclose that code by *...; or by /*....*/.
If you prefer the 2nd method, than you can easily find that specific code if you mark it as::
/*DEBUG*/ ... any debugging code ...
You have to consider the entire example, and put it in a larger context.
Context: Suppose you have 10 PROC PRINTs and 5 PROC CONTENTs that you want to run only if there is trouble. It's a lot of work to find and either comment or uncomment 15 procedures. And you might miss one or two. Instead, you can set up a macro variable that automatically turns all 15 procedures on or off.
Example: In the code that you posted, there was some careful work done beforehand when composing the program. You can't just switch a macro variable on or off and expect it to do anything at all. You have to build it into the program. In your sample code, the programmer built in a macro condition: %if &_ERROR %then ..... That was part of the planning, and part of the program that lets the setting of &_ERROR control whether or not the PROC PRINT executes.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: