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

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ChrisHemedinger
Community Manager

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;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.

View solution in original post

8 REPLIES 8
ChrisHemedinger
Community Manager

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.

Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
cfrey73
Fluorite | Level 6

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.

cfrey73
Fluorite | Level 6
I checked there, didn't see anything about who created the table
ChrisHemedinger
Community Manager

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;
Learn from the Experts! Check out the huge catalog of free sessions in the Ask the Expert webinar series.
cfrey73
Fluorite | Level 6
thanks chris! your solution was exactly what I was looking for.
Reeza
Super User
What's your OS?
You can use FINFO functions but if you have XCMD enabled you can also query it from the OS commands
cfrey73
Fluorite | Level 6
Operating inside of a virtual environment set up by CMS, which is running 7, unfortuanlty they limit our permissions to do basically anything useful, so it has to be limited to stuff I can query in SAS EG, and they have also disabled x commands so I can't go that route

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

What is Bayesian Analysis?

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 9982 views
  • 7 likes
  • 3 in conversation