Chapter Contents |
Previous |
Next |
%SYSFUNC and %QSYSFUNC |
Type: | Macro functions |
Syntax |
%SYSFUNC (function(argument(s))<,format>) |
%QSYSFUNC (function(argument(s))<,format>) |
All SAS functions, except those listed in the table SAS Functions Not Available with %SYSFUNC and %QSYSFUNC, can be used with %SYSFUNC and %QSYSFUNC.
You cannot nest functions to be used with a single %SYSFUNC. However, you can nest %SYSFUNC calls, for example,
%let x=%sysfunc(trim(%sysfunc(left(&num))));
Appendix 3, "Syntax for the Selected SAS Functions Used with %SYSFUNC," in SAS Macro Language: Reference, shows the syntax of SAS functions introduced with Release 6.12 used with %SYSFUNC.
Details |
Because %SYSFUNC is a macro function, you do not need to enclose character values in quotation marks as you do in DATA step 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. These statements show the difference:
dsid=open("sasuser.houses","i");
dsid=open("&mydata","&mode");
%let dsid = %sysfunc(open(sasuser.houses,i));
%let dsid=%sysfunc(open(&mydata,&mode));
All arguments in DATA step functions within %SYSFUNC must be separated by commas. You cannot use argument lists preceded by the word OF.
%SYSFUNC does not mask special characters or mnemonic operators in its result. %QSYSFUNC masks the following special characters and mnemonic operators in its result:
& % ' " ( ) + - * / < > = ¬ ^ ~ ; , blank AND OR NOT EQ NE LE LT GE GT
When a function called by %SYSFUNC or %QSYSFUNC requires a numeric argument, the macro facility converts the argument to a numeric value. %SYSFUNC and %QSYSFUNC can return a floating point number when the function they execute supports floating point numbers.
DIF | DIM | HBOUND |
IORCMSG | INPUT | LAG |
LBOUND | MISSING | PUT |
RESOLVE | SYMGET | All Variable Information Functions |
Note: Intead of INPUT and PUT,
which are
not available with %SYSFUNC and %QSYSFUNC, use INPUTN, INPUTC, PUTN, and PUTC
in Screen Control Language.
Note: The Variable
Information functions include functions such as VNAME and VLABEL. For a complete
list, see "Functions and CALL Routines" in SAS Language Reference: Dictionary.
Comparisons |
%QSYSFUNC masks the same characters as the %NRBQUOTE function.
Examples |
title "%sysfunc(date(),worddate.) Absence Report";
Executing this statement on July 18, 2000, produces this TITLE statement:
title "July 18, 2000 Absence Report"
proc format; value category Low-<0 = 'Less Than Zero' 0 = 'Equal To Zero' 0<-high = 'Greater Than Zero' other = 'Missing'; run; %macro try(parm); %put &parm is %sysfunc(putn(&parm,category.)); %mend; %try(1.02) %try(.) %try(-.38)
Executing this program writes these lines to the SAS log:
1.02 is Greater Than Zero . is Missing -.38 is Less Than Zero
%SYSFUNC executes the TRANSLATE function to translate the Ns in a string to Ps.
%let string1 = V01N01-V01N10; %let string1 = %sysfunc(translate(&string1,P, N)); %put With N translated to P, V01N01-V01N10 is &string1;
Executing these statements writes these lines to the SAS log:
With N translated to P, V01N01-V01N10 is V01P01-V01P10
%macro checkds(dsn); %if %sysfunc(exist(&dsn)) %then %do; proc print data=&dsn; run; %end; %else %put The data set &dsn does not exist.; %mend checkds; %checkds(sasuser.houses)
Executing this program produces the statements:
PROC PRINT DATA=SASUSER.HOUSES; RUN;
Many solutions have been generated in the past to obtain the number of variables and observations present in a SAS data set. Most past solutions have utilized a combination of _NULL_ DATA steps, SET statement with NOBS=, and arrays to obtain this information. Now, you can use the OPEN and ATTRN functions to obtain this information quickly and without interfering with step boundary conditions.
%macro obsnvars(ds,nvarsp,nobsp); %global dset nvars nobs; %let dset=&ds; %let dsid = %sysfunc(open(&dset)); %if &dsid %then %do; %let nobs =%sysfunc(attrn(&dsid,NOBS)); %let nvars=%sysfunc(attrn(&dsid,NVARS)); %let rc = %sysfunc(close(&dsid)); %end; %else %put Open for data set &dset failed - %sysfunc(sysmsg()); %mend obsnvars; %obsnvars(sasuser.houses,nvars,nobs) %put &dset has &nvars variable(s) and &nobs observation(s).;
Executing this program writes these lines to the SAS log:
sasuser.houses has 6 variable(s) and 15 observation(s).
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.