BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
dardodds
Fluorite | Level 6

We have a mixed environment.  We use Enterprise Guide connected to a SASApp ( 9.04.01M4P110916) server (windows X64_SR12R2) to prep our data.  Then we us SAS Visual Analytics for reporting and analysis and SAS Studio for the odd coding tweaking.

 

We need to have an easy way to get a list of libraries and their librefs. I tried proc contents _all_ it does not list all the libraries, just SAS libraries.  This is the code I have tried 

proc sql noprint;                                                                                                                       

   create table one as                                                                                                                  

     select * from dictionary.libnames;                                                                                                 

quit;                                                                                                                                   

                                                                                                                                        

proc print;                                                                                                                             

run;   

 

Again it only lists the SAS libraries but no user libraries.  Any ideas how to get a full list of libraries in SASApp and their librefs?

Thanks

Darlene

                                                                                                 

1 ACCEPTED SOLUTION

Accepted Solutions
dardodds
Fluorite | Level 6

I got some assistance from SAS Technical help and here is the code that worked for me.

 

data metadata_libraries;

length liburi upasnuri $256 name $128 type id $17 libref engine $8 path mdschemaname schema $256;

keep name libref engine path mdschemaname schema;

call missing(liburi,upasnuri,name,engine,libref);

nlibobj=1;

librc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",nlibobj,liburi);

do while (librc>0);

rc=metadata_getattr(liburi,'Name',name);

rc=metadata_getattr(liburi,'Engine',engine);

rc=metadata_getattr(liburi,'Libref',libref);

n=1;

uprc=metadata_getnasn(liburi,'UsingPackages',n,upasnuri);

if uprc > 0 then do;

call missing(type,id,path,mdschemaname,schema);

 

rc=metadata_resolve(upasnuri,type,id);

if type='Directory' then do;

rc=metadata_getattr(upasnuri,'DirectoryName',path);

output;

end;

else if type='DatabaseSchema' then do;

rc=metadata_getattr(upasnuri,'Name',mdschemaname);

rc=metadata_getattr(upasnuri,'SchemaName',schema);

output;

end;

n+1;

uprc=metadata_getnasn(liburi,'UsingPackages',n,upasnuri);

end;

nlibobj+1;

librc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",nlibobj,liburi);

end;

run;

 

View solution in original post

4 REPLIES 4
LinusH
Tourmaline | Level 20
What do you mean <exactly> with libraries?
Physically, and directory that holds a SAS file can be considered a library...
SAS code finds libraries that are assigned in the current session.
Another angle is to consider libraries that are registered in metadata.
Data never sleeps
Cynthia_sas
SAS Super FREQ
Also, if you have a SASApp server and are using VA, there is a very good chance that your libraries are defined in the Metadata and controlled by the authorization settings in the Metadata.

So, you might have to use SAS Management Console to see the libraries that are defined.

cynthia
dardodds
Fluorite | Level 6

Thanks for the reply.  We already use SAS Management Console to manage libraries.  The reason we need code to get a list of libraries is we are trying to write a report to automatically update the list of librefs that we need.  it's easy to get the librefs in Enterprise Guide but not so straightforward in SAS Studio.  So that's why we need to have a code snippet that will provide it.

dardodds
Fluorite | Level 6

I got some assistance from SAS Technical help and here is the code that worked for me.

 

data metadata_libraries;

length liburi upasnuri $256 name $128 type id $17 libref engine $8 path mdschemaname schema $256;

keep name libref engine path mdschemaname schema;

call missing(liburi,upasnuri,name,engine,libref);

nlibobj=1;

librc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",nlibobj,liburi);

do while (librc>0);

rc=metadata_getattr(liburi,'Name',name);

rc=metadata_getattr(liburi,'Engine',engine);

rc=metadata_getattr(liburi,'Libref',libref);

n=1;

uprc=metadata_getnasn(liburi,'UsingPackages',n,upasnuri);

if uprc > 0 then do;

call missing(type,id,path,mdschemaname,schema);

 

rc=metadata_resolve(upasnuri,type,id);

if type='Directory' then do;

rc=metadata_getattr(upasnuri,'DirectoryName',path);

output;

end;

else if type='DatabaseSchema' then do;

rc=metadata_getattr(upasnuri,'Name',mdschemaname);

rc=metadata_getattr(upasnuri,'SchemaName',schema);

output;

end;

n+1;

uprc=metadata_getnasn(liburi,'UsingPackages',n,upasnuri);

end;

nlibobj+1;

librc=metadata_getnobj("omsobj:SASLibrary?@Id contains '.'",nlibobj,liburi);

end;

run;

 

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 5615 views
  • 4 likes
  • 3 in conversation