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

Joe
  • 62,789
  • 6
  • 49
  • 67
blue and grey
  • 393
  • 7
  • 21
  • Why do you want to do math on macro variables? – Joe Apr 08 '13 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. – blue and grey Apr 08 '13 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 08 '13 at 16:49

1 Answers1

4

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

Longfish
  • 7,582
  • 13
  • 19