Published on :
Macro SASHELP

mf_existfunction Macro

This code is also available in: Deutsch Español Français
This macro searches for the name of a function provided as a parameter in the SASHELP.VFUNC system view. It returns 1 if the function is found, and 0 otherwise. The author notes that execution can be slow as it requires opening the sashelp.vfuncs table.
Data Analysis

Type : SASHELP


Uses the sashelp.vfunc system view to check for the function's existence.

1 Code Block
MACRO
Explanation :
The macro opens the SASHELP.VFUNC table, filtered by the function name (in uppercase). It attempts to retrieve an observation with %sysfunc(fetch). If fetch returns 0 (success), it means the function exists. The boolean result (1 or 0) is returned via %sysevalf.
Copied!
1%macro mf_existfunction(name)/*/STORE SOURCE*/;
2 
3 %local dsid rc exist;
4 %let dsid=%sysfunc(open(sashelp.vfunc(where=(fncname="%upcase(&name)"))));
5 %let exist=1;
6 %let exist=%sysfunc(fetch(&dsid, NOSET));
7 %let rc=%sysfunc(close(&dsid));
8 
9 %sysevalf(0 = &exist)
10 
11%mend mf_existfunction;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.