How do you add a number to a macro variable?

Answers were Sorted based on User's Feedback



How do you add a number to a macro variable?..

Answer / saurabh gupta

To add a number in macro use %EVAL macro

Example

%Let a= 2;
%Let b= 3;
%Let c= &a + &b ;
then it will give you value

c=2 + 3

but If you will use %eval it will give you sum

%Let c= %eval(&a + &b)
Now this will give you the correct answer

c=5

Is This Answer Correct ?    15 Yes 0 No

How do you add a number to a macro variable?..

Answer / kavitha

USING %EVAL FUNCTION
%let i=%eval(&i+1);

Is This Answer Correct ?    3 Yes 1 No

How do you add a number to a macro variable?..

Answer / nani

%macro add(a,b);
%if (%datatyp(&a)=NUMERIC and %datatyp(&b)=NUMERIC) %then %
do;
%put The result is %sysevalf(&a+&b).;
%end;
%else %do;
%put Error: Addition requires numbers.;
%end;
%mend add;

You can invoke the ADD macro as:

%add(5.1E2,225)

Is This Answer Correct ?    1 Yes 1 No

Post New Answer

More SAS Interview Questions

what is pdv? how it is related to input buffer in sas?

5 Answers   HSBC, Satyam,


what do the pad and dim functions do? : Sas programming

0 Answers  


Enlist the functions performed by sas.

0 Answers  


What are the statements that are executed only?

0 Answers  


Name types of category in which SAS Informats are placed?

0 Answers  


what is hash files in sas and why we are using this one in sas?

0 Answers   L&T, SAS,


How does the internal authentication work in sas? : sas-grid-administration

0 Answers  


What is shift table? have you ever created shift that?

2 Answers   Accenture, Clinical Research, Quintiles,


Can anyone help to find a statement to get all the predefined formats?

3 Answers   Verinon Technology Solutions,


Name and describe three SAS functions that you have used, if any?

2 Answers  


If reading an external file to produce an external file, what is the shortcut to write that record without coding every single variable on the record?

7 Answers   Accenture,


do you prefer proc report or proc tabulate? Why? : Sas programming

0 Answers  


Categories