BookmarkSubscribeRSS Feed
Ndclary
Calcite | Level 5
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
2 REPLIES 2
JackHamilton
Lapis Lazuli | Level 10
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
deleted_user
Not applicable
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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1073 views
  • 0 likes
  • 3 in conversation