- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
Is there any simple way to show values of all function parameters?
Ex. I have the following program:
data mydata;
...
x = finance('xirr', a, b, c, d, e, f, g, h, i, j, 0.1);
..
run;
Of cause, I can use put instructions just before function calling
data mydata;
...
put a=;
put b=;
put c=;
put d=;
put e=;
put f=;
put g=;
put h=;
put i=;
put j=;
x = finance('xirr', a, b, c, d, e, f, g, h, i, j, 0.1);
...
run;
But can I add some single instruction (or option) to automatically show all values of function parameters in log when it is executed? Ex. option mlogic allows us printing all values of macro parameters. May be there is some analogue of this option for SAS functions.
Thanks!
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use a variable list.
Your function call
x = finance('xirr', a, b, c, d, e, f, g, h, i, j, 0.1);
could also be written as
x = finance('xirr',of a b c d e f g h i j 0.1);
So put that list of variables/values into a macro variable and use it in both the assignment statement and a PUT statement.
%let varlist= a b c d e f g h i j;
...
x = finance('xirr',of &varlist 0.1);
put (x &varlist) (=);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi Dimitri,
I wish there was. But, caveat emptor, there isn't. You could shorten your example of putting all variables by using
put _all_;
But that's as good as it gets.
Regards,
-- Jan.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If you like you can code:
array arg {*} a b c d e f g h i;
do _m_ = 1 to dim(arg);
put strip(vname(arg(_M))) ' = ' arg(_M_);
end;
drop _m_;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
@DmitryErshov wrote:
data mydata; ... put a=; put b=; put c=; put d=; put e=; put f=; put g=; put h=; put i=; put j=; x = finance('xirr', a, b, c, d, e, f, g, h, i, j, 0.1); ... run;
Hello @DmitryErshov,
put (a--j)(=);
would not only be shorter code, but normally also take up less space in the log. However, it requires that a is the first and j the last variable of the list in the order of their logical position in the data set (see PROC CONTENTS output with VARNUM option).
In many practical applications SAS handles so many observations that such log output would become unwieldy. A common situation where it is very useful to display variable values and to see how they change during a DATA step is the debugging process. The data step debugger does have this functionality. Please see this post for a brief instruction: https://communities.sas.com/t5/SAS-Programming/use-of-index/m-p/264460#M51865.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you very much for your replies!
Regards,
Dmitry
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Use a variable list.
Your function call
x = finance('xirr', a, b, c, d, e, f, g, h, i, j, 0.1);
could also be written as
x = finance('xirr',of a b c d e f g h i j 0.1);
So put that list of variables/values into a macro variable and use it in both the assignment statement and a PUT statement.
%let varlist= a b c d e f g h i j;
...
x = finance('xirr',of &varlist 0.1);
put (x &varlist) (=);
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
macro, something like
%mycaller( functionname, parm1= value, parm2= value, parm= value...... )
The %mycaller macro is designed to call the regular function named as the positional parameter. The design needs to use the syspbuf macro option to support whatever parameter list the function needs. To support stable code which doesnt change when function parameter reporting is no longer needed, some trigger (for example a special macro parameter, alternatively it could be a macro var in global or the calling environment) needs to indicate whether or not the macro is to report the parameter values (at runtime not compile time). As this implies a separate (put) statement unfortunately the %mycaller macro cannot be a (my preference) function macro
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content