I am looking to grab the owner of each table in a shared library and output the table and owner into a dataset so that we can use it to audit. I have looked into the proc contents procedure, which looks like it can get you the owner, but I don't see any way to get that into a table using either the out or out2 statements. Any help would be useful
proc contents data = lib._ALL_ memtype=data out=out_data;
run;
I'm not sure that Owner is always the same as "who created it", but if you need the OS owner field for each table you could try this with PROC DATASETS -- using the same ODS TRACE/OUTPUT technique.
ods trace on;
ods output EngineHost=WithOwner;
proc datasets lib=sashelp;
contents data=_ALL_;
quit;
data WithOwner;
set WithOwner (where=(label1 in ('Filename' 'Owner Name')));
run;
Using ODS TRACE, you can find the table names of the output you see in the ODS destination.
ods trace on; LOG: Output Added: ------------- Name: Directory Label: Directory Information Template: Base.Datasets.Directory Path: Contents.Directory
From this, you can use ODS OUTPUT to add this table to your output data sets.
ods output directory=withowner;
proc contents data = sashelp._ALL_ memtype=data out=out_data;
run;
The WITHOWNER table will contain what you need.
Thanks, it looks like this gives the owner of the directory, is there another command to get the owner/creator of each individual dataset within the directory, or even just to get a single table and I could write a loop over the directory.
I'm not sure that Owner is always the same as "who created it", but if you need the OS owner field for each table you could try this with PROC DATASETS -- using the same ODS TRACE/OUTPUT technique.
ods trace on;
ods output EngineHost=WithOwner;
proc datasets lib=sashelp;
contents data=_ALL_;
quit;
data WithOwner;
set WithOwner (where=(label1 in ('Filename' 'Owner Name')));
run;
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.