BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DmitryErshov
Obsidian | Level 7

 

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!

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

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) (=);

 

View solution in original post

8 REPLIES 8
jklaverstijn
Rhodochrosite | Level 12

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.

Shmuel
Garnet | Level 18

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_;
FreelanceReinh
Jade | Level 19

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

DmitryErshov
Obsidian | Level 7

Thank you very much for your replies!

 

Regards,

Dmitry

Reeza
Super User
And you can use _numeric_ or _character_ to refer to numeric or character variables.
Tom
Super User Tom
Super User

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) (=);

 

Peter_C
Rhodochrosite | Level 12
If you wish this effect, you could implement a base was macro
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

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 8 replies
  • 1376 views
  • 10 likes
  • 7 in conversation