Solved
Contributor
Posts: 28

# sum of macro variables

Hi, I have two macro variables &a and &b. I have to sum these two macro variables and assign it to other macro variable name &c. How do I do that? Please help me.

Accepted Solutions
Solution
a week ago
PROC Star
Posts: 1,820

## Re: sum of macro variables

``````%let a=1.4;
%let b=1.6;

%let c=%sysevalf(&a+&b);

%put  &=c;``````

All Replies
Super User
Posts: 10,271

## Re: sum of macro variables

Use %eval:

``%let c = %eval(&a+&b);``
---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
How to convert datasets to data steps
How to post code
Super User
Posts: 5,884

## Re: sum of macro variables

Take a look at %eval.
Data never sleeps
Posts: 3,042

## Re: sum of macro variables

[ Edited ]

%eval works only on integers. If &b has a value of 7.5, you get an error. In that case, you could use %sysevalf

but you'd still be better off doing anything more advanced than integer arithmetic in a data step

--
Paige Miller
Contributor
Posts: 28

## Re: sum of macro variables

a and b will have decimal values too. can you help me  the statement for that part too?

Super User
Posts: 23,754

## Re: sum of macro variables

He did, %SYSEVALF.

Posts: 3,042

## Re: sum of macro variables

@VISHNU239 wrote:

a and b will have decimal values too. can you help me  the statement for that part too?

Do the math in a data step

--
Paige Miller
Solution
a week ago
PROC Star
Posts: 1,820

## Re: sum of macro variables

``````%let a=1.4;
%let b=1.6;

%let c=%sysevalf(&a+&b);

%put  &=c;``````
Contributor
Posts: 28