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

Difference between SAS STATA & SPSS?

0 Answers  


Describe the function and utility of the most difficult SAS macro that you have written?

0 Answers   Oracle,


I use NOCUM/NOPERCENT option in the tables statement like this Proc freq data = deepak; tables x y /nocum nopercent; run; Here I get nopercent and nocum in the output only for variables x and y. How do i do it for all variables? Deepak

1 Answers  


What are the five ways to do a table lookup in sas? : sas-grid-administration

0 Answers  


If you use a symput in a data step, when and where can you use the macro variable? : sas-macro

0 Answers  






What is highest missing value for numeric?

1 Answers  


what is transformation in sas data integration? : Sas-di

0 Answers  


How to limit decimal places for the variable using proc means?

0 Answers  


what is the difference between %put and symbolgen?

6 Answers  


what is TAB delimiter? explain about it? what will you do to get TAB delimiter?

3 Answers   Cap Gemini,


How experienced are you with customized reporting and use of Data _Null_ features?

4 Answers   Oracle,


How would you compile all macros from a folder in a study, within the autoexec program?

1 Answers  


Categories