I'm building a utility that leverages the SAS metadata ID (or URI) of a table object. The following code works fine for getting the ID when the library uses the BASE engine:
%let mylib=SOMELIB;
data output (keep=uri dataname);
length uri $100 dataname $256;
uri='';
i=1;
do until (rc<0);
rc=metadata_getnasn("omsobj:SASLibrary?@Libref='&mylib'","Tables",i,uri);
put rc=;
prc=metadata_getattr(uri,"Name",dataname);
if rc>=0 then output;
i+1;
put i=;
end;
run;
However for other library engines (eg OLEDB, ODBC, REMOTE) SAS will store the information in different properties (eg under "UsingPackages/[my db]/Tables"). I can write conditional logic for each of the library engines I come across, but wondered if there was an easier / more generic way to get the Table ID?
The same issue occurs in reverse (if I search for the Table I still need the SASLibrary to ensure it is unique).
The code in this article was extremely helpful for our SAS admins:
http://support.sas.com/documentation/cdl/en/lrmeta/63180/HTML/default/viewer.htm#p1k9zipe59ha2an1pq34gu143lay.htm
It'll give you everything you want and more.
This is the code I used in the end (inspired from this post). It also returns the metadata folder path for each table. It doesn't have 100% coverage of the estate, but is fine for my utility. I'd also point out that it uncovered a handful of instances where we had more than one table (with the same name) registered with the same library. Worth having in the test harness!