Using SAS Language Functions in the DATA Step
and Macro Facility
The macro functions %SYSFUNC and %QSYSFUNC can call SAS language functions
and functions written with SAS/TOOLKIT software to generate text in the macro
facility. %SYSFUNC and %QSYSFUNC have one difference: the %QSYSFUNC masks
special characters and mnemonics and %SYSFUNC does not. For more information
about these functions, see “%SYSFUNC and %QSYSFUNC Functions” on page 283.
%SYSFUNC arguments are a single SAS language function and an optional format. See
the following examples:
%sysfunc(date(),worddate.)
%sysfunc(attrn(&dsid,NOBS))
You cannot nest SAS language functions within %SYSFUNC. However, you can nest
%SYSFUNC functions that call SAS language functions, as in the following statement:
%sysfunc(compress(%sysfunc(getoption(sasautos)),%str(%)%(%')))
This example returns the value of the SASAUTOS= system option, using the
COMPRESS function to eliminate opening parentheses, closing parentheses, and single
quotation marks from the result. Note the use of the %STR function and the unmatched
parentheses and quotation marks that are marked with a percent sign (%).
All arguments in SAS language functions within %SYSFUNC must be separated by
commas. You cannot use argument lists preceded by the word OF.
Because %SYSFUNC is a macro function, you do not need to enclose character values
in quotation marks as you do in SAS language functions. For example, the arguments to
the OPEN function are enclosed in quotation marks when the function is used alone but
do not require quotation marks when used within %SYSFUNC.
Here are some examples of the contrast between using a function alone and within
%SYSFUNC:
dsid = open("Sasuser.Houses","i");
dsid = open("&mydata","&mode");
%let dsid = %sysfunc(open(Sasuser.Houses,i));
%let dsid = %sysfunc(open(&mydata,&mode));
You can use %SYSFUNC and %QSYSFUNC to call all of the DATA step SAS
functions except the ones that are listed in Table 17.2 on page 284. In the macro facility,
SAS language functions called by %SYSFUNC can return values with a length up to
32K. However, within the DATA step, return values are limited to the length of a data set
character variable.
The %SYSCALL macro statement enables you to use SAS language CALL routines
with the macro processor, and it is described in “Macro Statements” on page 301.
108 Chapter 8 Interfaces with the Macro Facility

Get SAS 9.4 Macro Language, 5th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.