4

I'd like to create a new macro variable from other macro variables that already exist.

I have tried multiple variations of call symput, %eval , and input to no avail...

I would like d to evaluate to 3 / 30 = .10.


*****  taken directly from the sas help files...  ;

%let a=1+2;
%let b=10*3;
%let c=5/3;
%let eval_a=%eval(&a);
%let eval_b=%eval(&b);
%let eval_c=%eval(&c);

%put &a is &eval_a;
%put &b is &eval_b;
%put &c is &eval_c; * not sure why this evaluates to 1, but I'm sure it's documented somewhere... ;


*****  This evaluates to 0...

%let d = %eval(%eval(&a) / %eval(&b)) ; 

%put &d ;

Thanks so much...

3
  • Why do you want to do math on macro variables?
    – Joe
    Apr 8, 2013 at 16:11
  • 1
    Our center uses an old SAS print macro to produce tables for reports. The tables are sketched out, and then we have to produce them. Many times, working in a dataset or using data steps works fine, but sometimes it is much faster to produce a value using this method. Apr 8, 2013 at 16:36
  • Ah, ok. Probably preaching to the choir, but if you have the opportunity to modernize, do - SAS tabulation options are 1000x better nowadays than what used to be required.
    – Joe
    Apr 8, 2013 at 16:49

1 Answer 1

5

%eval will only return an integer. To get the decimal, you need to use %sysevalf.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.