The SAS Output Delivery System and reporting techniques

Macro Variables

Reply
N/A
Posts: 1

Macro Variables

I have a macro that recursivly runs some functions. I noticed that the macro variables are actually the functions themselves, instead of the values. Is there a way to force them to become values?

For instance:

%let x=1
%let Piece1=(&x+1);
%let Piece2=(&x+2);

%let equation=(&Piece1/&Piece2);

Now what I want is for equation to equal .666 ... what I get is (1+1)/(1+2)

How can I force the variable to be the value instead of the equation?

Thanks!

Noble
Frequent Contributor
Posts: 102

Re: Macro Variables

You might take a look at the %SYSEVALF macro function, which evaluates an expression and returns a floating point result.

support.sas.com/onlinedoc/913/getDoc/en/mcrolref.hlp/a000206831.htm
N/A
Posts: 0

Re: Macro Variables

Hi,

Also, if you use call symput instead of %let, then you can pass an expression or variable instead of a literal string. For example, instead of:

%let equation=(&Piece1/&Piece2);

you would use:

call symput('equation',&piece1/&piece2);

Please note that call symput only works within a data step, so you could do something like:

data _null_;
call symput('equation',&piece1/&piece2);
run;

Thanks,
Mark
Ask a Question
Discussion stats
  • 2 replies
  • 114 views
  • 0 likes
  • 3 in conversation