How do you add a number to a macro variable?
Answers were Sorted based on User's Feedback
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 |
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 |
Difference between SAS STATA & SPSS?
Describe the function and utility of the most difficult SAS macro that you have written?
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
What are the five ways to do a table lookup in sas? : sas-grid-administration
If you use a symput in a data step, when and where can you use the macro variable? : sas-macro
What is highest missing value for numeric?
what is transformation in sas data integration? : Sas-di
How to limit decimal places for the variable using proc means?
what is the difference between %put and symbolgen?
what is TAB delimiter? explain about it? what will you do to get TAB delimiter?
How experienced are you with customized reporting and use of Data _Null_ features?
How would you compile all macros from a folder in a study, within the autoexec program?