I have a lot of code which trawls through the metadata repository to find, well, all sorts of useful stuff: tables, columns, dependencies, transformation templates - that sort of thing. But it only works reliably on the Foundation repository - which is mostly what I want to look at anyway.
But I'm introducing a new facility for other developers to be able to look at the results of jobs, and for that the code needs to look at the developer's own repository - what they've checked out in DI, for example. How can I work out from the datastep metadata functions what repository they're using? Not all repository ids map on to userids, unfortunately. I'm most of the way there with metadata_resolve, but not quite.
Find below some general code to list all project repositories and their owner.
data md_project_repo_owner;
length
nRep 8
type etype $ 32
id eId $ 32
repSearch $ 128
repURI $ 128
repName $ 128
repPath $ 1024
extSearch $ 1024
ownerURI $ 128
ownerId $ 64
;
call missing(type, etype, id, eid, repSearch, repURI, repName, repPath, extSearch, ownerURI);
*
* search for Project repositories
*;
repSearch = "OMSOBJ:Repository?@RepositoryType = 'Project'";
nRep = metadata_resolve(repSearch, type, id);
putlog "NOTE: Number of Objects found for" +1 repSearch= nRep=;
*
* get the individual repURI for each entry
*;
do objN = 1 to nRep;
rc = metadata_getnobj(repSearch, objN, repURI);
*
* get Object type and id from objURI
*;
eObjType = scan(repURI, 2, ":\");
eObjId = scan(repURI, 2, "\");
*
* get repository details
* more attributes are available
*;
rc = metadata_getattr(repURI, "Name", repName);
rc = metadata_getattr(repURI, "Path", repPath);
*
* search Extension objects
*;
extSearch = cats("OMSOBJ:Extension?@Name='ProjectRepository' and @Value=", quote(strip(eObjId), "'"));
nExt = metadata_resolve(extSearch, etype, eid);
*
* get the owner object
*;
rc = metadata_getnasn(eId, "OwningObject", 1, ownerURI);
*
* get owner id
*;
rc = metadata_getattr(ownerURI, "Name", ownerId);
output;
end;
keep repURI repName repPath ownerURI ownerId;
run;
Find below some general code to list all project repositories and their owner.
data md_project_repo_owner;
length
nRep 8
type etype $ 32
id eId $ 32
repSearch $ 128
repURI $ 128
repName $ 128
repPath $ 1024
extSearch $ 1024
ownerURI $ 128
ownerId $ 64
;
call missing(type, etype, id, eid, repSearch, repURI, repName, repPath, extSearch, ownerURI);
*
* search for Project repositories
*;
repSearch = "OMSOBJ:Repository?@RepositoryType = 'Project'";
nRep = metadata_resolve(repSearch, type, id);
putlog "NOTE: Number of Objects found for" +1 repSearch= nRep=;
*
* get the individual repURI for each entry
*;
do objN = 1 to nRep;
rc = metadata_getnobj(repSearch, objN, repURI);
*
* get Object type and id from objURI
*;
eObjType = scan(repURI, 2, ":\");
eObjId = scan(repURI, 2, "\");
*
* get repository details
* more attributes are available
*;
rc = metadata_getattr(repURI, "Name", repName);
rc = metadata_getattr(repURI, "Path", repPath);
*
* search Extension objects
*;
extSearch = cats("OMSOBJ:Extension?@Name='ProjectRepository' and @Value=", quote(strip(eObjId), "'"));
nExt = metadata_resolve(extSearch, etype, eid);
*
* get the owner object
*;
rc = metadata_getnasn(eId, "OwningObject", 1, ownerURI);
*
* get owner id
*;
rc = metadata_getattr(ownerURI, "Name", ownerId);
output;
end;
keep repURI repName repPath ownerURI ownerId;
run;
**bleep**, you're good! That's exactly what I needed.
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
Explore Now →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.