DATA Step, Macro, Functions and more

Function to determine type of library member

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 5
Accepted Solution

Function to determine type of library member

Is there a function to determine the type of a library member? I don't want to use dictionary tables (this information is in sashelp.vmember) but instead want to use (if possible) a funtion. For example:

 

type = function('work.sasmacr');

put type=;

 

would print 'CATALOG'  to the log.

 

 


Accepted Solutions
Solution
‎03-18-2016 10:45 AM
Super User
Posts: 5,254

Re: Function to determine type of library member

If it's important not to use submitted Sas code, you could browse sashelp.vmember by function calls. Very awkward IMO but should meet your requirements.
Data never sleeps

View solution in original post


All Replies
Super User
Super User
Posts: 7,392

Re: Function to determine type of library member

There isn't a function for this, why would you need one, there is only datasets and catalogs?  Use the metadata libraries to ascertain these, why not?

data _null_;
  set sashelp.vmember (where=(libname="SASHELP" and MEMNAME="AC"));
  put memtype;
run;
Super User
Posts: 5,254

Re: Function to determine type of library member

No, not in the function list.

Please state why you don't wish to use system tables.

Data never sleeps
Occasional Contributor
Posts: 5

Re: Function to determine type of library member

Using SCL I want to delete all member from the work library. This is my program:

 

init:
dcl sashelp.classes.sasfilelist_c.class memobj;
dcl num rc i memcount;
dcl char member;

memobj = _new_ sashelp.classes.sasfilelist_c();
memobj.library = 'work';
memcount = memobj._count();
do i = 1 to memcount;
member= memobj._getItem(i);
rc = delete(member);
end;

memobj._term();
return;

 

But this will only delete data sets because the 'delete'-function takes as second argument the member type (default is data set). So I need to know the member type to pass to the delete statement in order to delete all members. 

 

I could do this in a submit-block using proc datasets but I don't want anything to appear in the log or log buffer.

 

By the way in response to RW9: there are more types than only data and catalog, for example view, mddb etc.

Super User
Super User
Posts: 7,392

Re: Function to determine type of library member

Ah, so your using SAS/AF.  I am afraid I haven't used that in many years, hadn't thought anyone was still using it.  I would suggest your best bet is still to do this in SAS code.  Best of luck.  

Super User
Posts: 3,101

Re: Function to determine type of library member

You could use the EXIST function on each member name. By default this checks for datasets. If it returns a 0 return code then you can assume that the member type is not DATA so you could then try EXIST for the member type CATALOG. It's a bit clunky but should work.

Super User
Posts: 6,928

Re: Function to determine type of library member

If you want to hide your actions from the log, consider writing a shell script and calling that with call system or X.

---------------------------------------------------------------------------------------------
Maxims of Maximally Efficient SAS Programmers
Solution
‎03-18-2016 10:45 AM
Super User
Posts: 5,254

Re: Function to determine type of library member

If it's important not to use submitted Sas code, you could browse sashelp.vmember by function calls. Very awkward IMO but should meet your requirements.
Data never sleeps
Occasional Contributor
Posts: 5

Re: Function to determine type of library member

Yes, I probably have to use dictionary tables. I'll solve it that way in combination with Ksharp's suggestion and write my own funtion.

Super User
Posts: 9,662

Re: Function to determine type of library member

Or Maybe you could use PROC FCMP + dictionary table to build such function .

Regular Contributor
Posts: 198

Re: Function to determine type of library member

this page contains code for each of the existence functions

 

http://www.sascommunity.org/wiki/Macro_Exist

 

I am still unclear how you are going to use this knowledge.

if you have a list of filename.ext of the files in a Windows folder,

then the extention tells you the type:

 

data: .sasbdat

 

catalog: sasbcat

 

Ron Fehd  reuse maven

Occasional Contributor
Posts: 5

Re: Function to determine type of library member

I am not interested in the existence, I know already the member exists. I want to know the type of a library member. As explained earlier I need that information because I want to delete member from SCL. And the scl delete function takes two arguments: name (the name of member to delete) and type (the type of member to delete).

Super User
Super User
Posts: 6,495

Re: Function to determine type of library member

If you have a variable MEMNAME with the name of the member then just loop over values of MEMTYPE in DATA, CATALOG, VIEW, ... and call the EXIST() function with MEMNAME and MEMTYPE until you find out what MEMTYPE to use for the call to the DELETE() function.

Occasional Contributor
Posts: 5

Re: Function to determine type of library member

That's not a very robust solution: what if SAS introduces a new type? Then you have to change the program to include the name of that new type. I prefer to use the dictionnary tables.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 13 replies
  • 397 views
  • 0 likes
  • 8 in conversation