DATA Step, Macro, Functions and more

sum of macro variables

Accepted Solution Solved
Reply
Contributor
Posts: 28
Accepted Solution

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

Posted in reply to VISHNU239
%let a=1.4;
%let b=1.6;

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

%put  &=c;

View solution in original post


All Replies
Super User
Posts: 10,271

Re: sum of macro variables

Posted in reply to VISHNU239

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

Posted in reply to VISHNU239
Take a look at %eval.
Data never sleeps
Respected Advisor
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

Posted in reply to PaigeMiller

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

Posted in reply to VISHNU239

He did, %SYSEVALF. 

Respected Advisor
Posts: 3,042

Re: sum of macro variables

Posted in reply to VISHNU239

@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

Posted in reply to VISHNU239
%let a=1.4;
%let b=1.6;

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

%put  &=c;
Contributor
Posts: 28

Re: sum of macro variables

Posted in reply to novinosrin

Thanks guys. it worked.

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 8 replies
  • 87 views
  • 5 likes
  • 6 in conversation