Reference: SAS support website (www.support.sas.com).
Many times we have seen that a Macro is being called from another macro . And we find it difficult to debug it if the outer macro is called in loop. In fact I have seen and designed some architecture where we have to do 4 to 5 level nesting within the macro.
Usually the 3 options that is used in Macro debugging are mprint mlogic symbolgen. The MPRINT option is an essential tool when developing macros
allowing you to see the SAS code generated by a macro within the log. If
however one macro makes a call to another which then generates SAS code, this
cannot easily be seen and recognized in the log. See below example:
SAS log generated by above code is given below, Inner macro is printed but difficult to understand the nesting
Log without MPRINTNEST:
Submitting the same macro
a second time but with the MPRINTNEST option included as well as the MPRINT
option provides details of the macro nesting in the log.
Log with MPRINTNEST:
It is now clear to see
that the second macro call is nested within the first, and if further nested
call are made this will also be displayed in the same format (macro name
separated by dots).
At the end, let me leave you with below exercise on macro variables. What will be the output ?
At the end, let me leave you with below exercise on macro variables. What will be the output ?
%LET A=7 ; %LET B=&A+2; %LET C=%EVAL(&A+2);
%LET D=%EVAL (&A+4.2);
%PUT &A &B &C &D;
Hey Thanks Ashutosh... This Blog is really interesting and found helpful.
ReplyDeletePlease find my below response on SAS exercise.
Once you submit the code, except &D it will resolve. So resolve value will be
&A--->7
&B--->7+2
&C--->9
For %LET D=%EVAL(&A+4.2) it will give you an error because
%eval will not handle floating number.
So if you want to handle floating number we should use
%sysevalf. Thanks