SASNAME will tell you if a name is a valid SASNAME
rc=SASNAME(name);
return code for the operation:
1 | The name is a valid SAS name. |
0 | The name is not a valid SAS name. |
Is there an equivalent SASFUNC(name) that will tell you if name is a valid function name in the current session?
If not and it was custom coded in FCMP is there a place to lookup available functions?
You need to be clearer what you are asking for.
The NAME of a function is a name that follows the original SAS naming rules. So if you want to test if a string's value is following those rules it is the same whether the name is to used for function or dataset or a variable. In that case use the NVALID() function with the optional second argument set to V7.
%let name=Fred;
%put valid_name =%sysfunc(nvalid(&name,v7));
But I think perhaps you are asking for something much different. Are you asking to know if there is a LIST of existing SAS defined functions? If that is your question I do not think such a list is available as part of SAS.
Or are you asking if there is a way to query a catalog you used with PROC FCMP to store some user defined functions? That might be possible using SASHELP.VCATALG or other dictionary views. Or perhaps using PROC CATALOG.
Correct, much different. Would like to test if name is the name of a function within context of session (i.e. installed products and fcmp cmplib)
As @Tom has already stated, I don't think there is such a SAS function for checking all available functions nor any way of implementing such a check yourself in FCMP. Why do you want such functionality?
Hello @RichardAD,
I think you can retrieve the names of SAS-supplied functions (and CALL routines) from DICTIONARY.FUNCTIONS and then add the names of user-defined functions (and, optionally, subroutines, see 'SUBROUTI' below) from the CMPLIB:
proc sql;
create table fncnames as
select fncname
from dictionary.functions
where fncname ne ' '
union
select scan(_key_,-1,'.')
from %sysfunc(getoption(cmplib))
where name in ('FUNCTION' 'SUBROUTI')
;
quit;
While it should be possible to load this dataset into a PROC FCMP array or hash object, you could also create a numeric informat
data infmt;
retain fmtname 'isfncname' type 'I' label 1 hlo 'U';
set fncnames(rename=(fncname=start)) end=last;
output;
if last then do;
hlo='O';
label=0;
output;
end;
run;
proc format cntlin=infmt;
run;
and then use the INPUT function to obtain the 1/0 flag for existing/non-existing function names:
data test;
input name :$20.;
fnflag=input(name,isfncname.);
cards;
cos
propcase
baseconvfp
other
;
In my SAS session there is a user-defined function BASECONVFP, but there is no function named "OTHER", so the result is this:
Obs name fnflag 1 cos 1 2 propcase 1 3 baseconvfp 1 4 other 0
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.
Early bird rate extended! Save $200 when you sign up by March 31.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.