1
0
mirror of https://github.com/sasjs/core.git synced 2026-01-05 08:30:06 +00:00

feat: new mf_existfunction macro

This commit is contained in:
Allan Bowe
2021-08-18 23:36:12 +03:00
parent bc410a9135
commit 005af0ecf8
2 changed files with 55 additions and 0 deletions

33
base/mf_existfunction.sas Normal file
View File

@@ -0,0 +1,33 @@
/**
@file
@brief Checks if a function exists
@details Returns 1 if the function exists, else 0
Usage:
%put %mf_existfunction(CAT);
%put %mf_existfunction(DOG);
Full credit to [Bart](https://sasensei.com/user/305) for the vfunc pointer
and the tidy approach for pure macro data set filtering.
Check out his [SAS Packages](https://github.com/yabwon/SAS_PACKAGES)
framework!
@param [in] name (positional) - function name
@author Allan Bowe
**/
/** @cond */
%macro mf_existfunction(name
)/*/STORE SOURCE*/;
%local dsid rc exist;
%let dsid=%sysfunc(open(sashelp.vfunc(where=(fncname="%upcase(&name)"))));
%let exist = %sysfunc(fetch(&dsid, NOSET));
%let rc = %sysfunc(close(&dsid));
%sysevalf(0 = &exist)
%mend mf_existfunction;
/** @endcond */