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

how do you read binary data in sas?

3 Answers   Satyam,


What are the special input delimiters used in SAS?

0 Answers  


What is the difference between reading data from an external file and reading data from an existing data set?

0 Answers  


what are the three main credit bureau names

1 Answers   Synchrony Financial,


Do we follow ADAM in analysis dataset development?How? Usually which version? Why is it necessary?

0 Answers  






How would you code a macro statement to produce information on the sas log? This statement can be coded anywhere? : sas-macro

0 Answers  


how can you create zero observation dataset? : Sas programming

0 Answers  


What commands are used in the case of including or excluding any specific variables in the data set?

0 Answers  


if a variable contain dates like "2015/01"---"2015/12" (yymm) ,How to add day to those dates,if them month is jan then 31 if the month is feb then 28 so on ...

0 Answers   Accenture,


How would you delete observations with duplicate keys?

13 Answers   Accenture,


If you?re not wanting any SAS output from a data step, how would you code the data statement to prevent SAS from producing a set?

1 Answers  


Which are SAS Windows Clients & SAS Java Clients

3 Answers   TCS,


Categories