SAS author's tip: Using the %SYSFUNC and %QSYSFUNC macro functions


This week’s author tip is from Michele Burlew and her new book SAS Macro Programming Made Easy, Third Edition. Burlew chose this tip because she says the %SYSFUNC and %QSYSFUNC functions allow you to use SAS language functions in macro programming. Access to these functions greatly increases macro programming power and can simplify writing macro code.

We hope you find this tip useful. You can also read an excerpt from Burlew’s book.

The functions %SYSFUNC and %QSYSFUNC apply SAS programming language functions to text and macro variables in your macro programming. Providing access to the many SAS language functions in your macro programming applications, %SYSFUNC and %QSYSFUNC greatly extend the power of your macro programming.

Since these two functions are macro language functions and the macro facility is a text-handling language, the arguments to the SAS programming language function are not enclosed in quotation marks; it is understood that all arguments are text. Also, the values returned through the use of these two functions are considered text.

Functions cannot be nested within one call to %SYSFUNC and %QSYSFUNC. Each function must have its own %SYSFUNC or %QSYSFUNC call, and these %SYSFUNC and %QSYSFUNC calls can be nested.

Using %SYSFUNC to Format a Date in the TITLE Statement

The TITLE statement in Example 6.5 shows how the elements of a date can be formatted using %SYSFUNC and the DATE SAS language function.

  "Sales for %sysfunc(date(),monname.) %sysfunc(date(),year.)";

On January 30, 2014, the title statement would resolve to

Sales for January 2014

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


About Author

Maggie Miller

Education and Training

+ Maggie Miller was formerly a communications specialist at SAS. You'll likely find her writing blogs, shooting videos and sharing it all on social media. She has nearly ten years of journalism experience that she brings to her writing to help you learn and grow with SAS. Follow on Twitter @maggiemiller0

Comments are closed.

Back to Top