BookmarkSubscribeRSS Feed
Doc_Duke
Rhodochrosite | Level 12
Hi,

I wanted to do a PROC CONTENTS and get the output for just the tables in a database referenced by a LIBNAME. When I run

PROC CONTENTS DATA=mylib._ALL_;

it show all the database views and queries as well (they are tagged as such in the "DBMS Member Type" column.). CONTENTS lists their "SAS" Member Type as DATA, so the MEMTYPE= option doesn't cut it.

Any other ideas of how to limit the output?

Thanks,
Doc Muhlbaier
Duke
3 REPLIES 3
Ksharp
Super User
Hi.
How about use dictionary.tables which also contain the information you want.
[pre]
proc sql;
select *
from dictionary.tables;
quit;
[/pre]


Ksharp
buckeye
Obsidian | Level 7
Following Ksharp's tip, it appears this should work:


LIBNAME DAT 'my:\mylib';

PROC SQL ;
SELECT DISTINCT 'PROC CONTENTS DATA =DAT.' || COMPRESS(MEMNAME,' ') || ';'
INTO :STR SEPARATED BY ' '
FROM DICTIONARY.COLUMNS WHERE MEMTYPE='DATA' ;
QUIT;

&STR;

RUN;

You may want to change the where clause as this:

WHERE MEMTYPE='DATA' AND MEMNAME LIKE 'mytbl%'

to list all tables with name begining 'mytbl'.

Hope this helps.
Doc_Duke
Rhodochrosite | Level 12
I figured it was in the DICTIONARY somewhere, though it took multiple tables to get it. I ultimately made it into a macro. I'm sure it could be further spiffed with error checking and such, but this will suit my purposes.

Doc

%MACRO DBMScontents(dbmslib,outtab=Contents);
* Print the contents of a DBMSs tables only;

* only keep column attributes that are informative via DBMS;
PROC SQL;
CREATE TABLE &outtab AS
SELECT col.memname,
col.varnum,
col.name,
col.type,
col.length,
col.format
FROM
dictionary.columns AS Col,
dictionary.tables AS table
WHERE table.dbms_memtype='TABLE'
AND table.libname =UPCASE("&dbmslib")
AND table.libname=col.libname
AND table.memname=col.memname
ORDER BY col.memname, col.name
;
QUIT;
RUN;

PROC PRINT DATA=&outtab NOOBS;
TITLE "Contents of Tables in LIBNAME &dbmslib";
BY memname;
PAGEBY memname;
RUN;

%MEND dbmscontents;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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
  • 3 replies
  • 7154 views
  • 0 likes
  • 3 in conversation