How to create new macro variable from existing macro variables using calculations in SAS?

StackOverflow https://stackoverflow.com/questions/15881864

  •  02-04-2022
  •  | 
  •  

Frage

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

War es hilfreich?

Lösung

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top