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

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 2 replies
  • 618 views
  • 0 likes
  • 3 in conversation