When working in the SAS Macro Language, you can use the **%eval()** function to evaluate logical expressions and perform integer arithmetic.

```
%let a = 3+5;
%let b = 10/5;
%let c = 10>3;
%let eval_a = %eval(&a);
%let eval_b = %eval(&b);
%let eval_c = %eval(&c);
%put &eval_a;
%put &eval_b;
%put &eval_c;
/* Output */
8
2
1
```

The SAS Macro Language allows us to create dynamic and powerful code which allows us to handle complicated code requirements.

One useful function from the SAS Macro Language is **%eval()**.

When working in the SAS Macro Language, you can use the **%eval()** function to evaluate logical expressions and perform integer arithmetic.

Macro variables are strings, and so if you have a string which represents an expression, **%eval()** can help you get the value of that evaluated expression.

Below are some examples of how you can use the **%eval()** function in SAS to evaluate different expressions.

```
%let a = 3+5;
%let b = 10/5;
%let c = 10>3;
%let eval_a = %eval(&a);
%let eval_b = %eval(&b);
%let eval_c = %eval(&c);
%put &eval_a;
%put &eval_b;
%put &eval_c;
/* Output */
8
2
1
```

## Using %eval() to Increment a Counter in a SAS Macro

One useful example of using the SAS Macro **%eval()** function is if you are using a loop and want to increment a counter.

If you are using a do loop in a SAS Macro, or just need to increment a SAS macro variable, you can use **%eval()**.

Below is an example of a do loop in a SAS Macro where we use **%eval()** to increment a counter variable.

```
%let counter = 0;
%macro loop_example();
%do i = 0 %to 3;
%put &counter;
%let counter = %eval(&counter+1);
%end;
%mend;
%loop_example();
/* Output */
0
1
2
3
```

Hopefully this article has been useful for you to learn how to use the SAS **eval()** function in the SAS Macro Language.

## Leave a Reply