SAS author's tip: macro functions %EVAL and %SYSEVALF


One of of my favorite reviewer quotes about Michele Burlew's book SAS Macro Programming Made Easy, Second Edition is[ It ] helps eliminate the 'fear factor' often associated with using macros, while offering valuable insight to programmers with a broad range of experience." --Suson vonLehmden, RTI International

I've worked with Michele Burlew for seven years and she continues to amaze me. She's a prolific writer, extremely knowledgeable about SAS, and one of the warmest people I've had the pleasure of getting to know at various user group events. While I won't get a chance to chat with Michele in person at a conference this fall,  I am featuring an excerpt from one of her very popular books this week!

The following excerpt is from SAS Press author Michele Burlew's book SAS Macro Programming Made Easy, Second Edition. Copyright © 2006,  SAS Institute Inc., Cary, North Carolina, USA. ALL RIGHTS RESERVED. (please note that results may vary depending on your version of SAS software)

Macro Evaluation Functions

The two macro evaluation functions, %EVAL and %SYSEVALF, evaluate arithmetic expressions and logical expressions. These expressions are comprised of operators and operands that the macro processor evaluates to produce a result. The arguments to one of these macro evaluation functions are temporarily converted to numbers so that a calculation (arithmetic or logical) can be completed. The macro evaluation function converts the result that it returns to text.

Arithmetic expressions use arithmetic operators such as plus signs and minus signs. Logical expressions use logical operators such as greater than signs and equal signs. The %EVAL function evaluates expressions using integer arithmetic. The %SYSEVALF function evaluates expressions using floating point arithmetic. Macro expressions are constructed with the same arithmetic and comparison operators found in the SAS language. A section in Chapter 7 discusses in more detail how to construct macro expressions. 

The syntax of the %EVAL function is

 %EVAL(arithmetic expression|logical expression)

 The syntax of the %SYSEVALF function is

%SYSEVALF(arithmetic expression|logical expression

By default, the result of the %SYSEVALF function is left as a number which is converted back to text. Otherwise, you can request %SYSEVALF to convert the result to a different format, as shown in Table 6.2. When requesting one of these four conversion types, specify the conversion type as the second argument to %SYSEVALF.

Visit Michele Burlew's author page to read a free chapter from this book, to learn about her upcoming book SAS Hash Objects: A Programmer's Guide, and to explore her entire volume of SAS Press books!


About Author

Shelly Goodin

Social Media Specialist, SAS Publications

Shelly Goodin is SAS Publications' social media marketer and the editor of "SAS Publishing News". She’s worked in the publishing industry for over thirteen years, including seven years at SAS, and enjoys creating opportunities for fans of SAS and JMP software to get to know SAS Publications' many offerings and authors.

Related Posts

Comments are closed.

Back to Top