BookmarkSubscribeRSS Feed
RichardAD
Quartz | Level 8

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?

 

 

4 REPLIES 4
Tom
Super User Tom
Super User

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.

RichardAD
Quartz | Level 8

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)

SASKiwi
PROC Star

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?  

FreelanceReinh
Jade | Level 19

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

sas-innovate-white.png

Register Today!

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.

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 276 views
  • 4 likes
  • 4 in conversation