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

Hello,

 

I'm looking to list all datasets in a library, variables and variable types along with the library name.

 

I've found this on this forum located here:https://communities.sas.com/t5/SAS-Procedures/PROC-CONTENTS-of-entire-library-with-all-variables-det...

 

Can someone please assist?

 

/* Note that value of libname is UPPERCASE */
proc sql;
create table columns as
select name as variable
,memname as table_name
from dictionary.columns
where libname = 'WORK'
;
quit;
1 ACCEPTED SOLUTION

Accepted Solutions
ghosh
Barite | Level 11
* Change SASHELP with the library name;

PROC CONTENTS DATA=SASHELP._ALL_ ; RUN; 

View solution in original post

5 REPLIES 5
ghosh
Barite | Level 11
* Change SASHELP with the library name;

PROC CONTENTS DATA=SASHELP._ALL_ ; RUN; 
heffo
Pyrite | Level 9

It all depends on what you want to do with it. If you want to do some coding then the proc sql is better. I'm doing an automatic metadata documentation of all the libraries, tables, variables and formats by a combination of queries to the dictionary tables. But if you only need to view them on off, then the proc datasets is perfect. 

proc sql;
	create table columns as
	select libname,	memname, name, type, length, varnum
	from dictionary.columns
	where libname = upcase('WORK') ;
quit;
Haydn
Quartz | Level 8
Hi everyone, is there a way using either of the methods above or a macro, where I could specify the files I want, without getting all of them?
heffo
Pyrite | Level 9
%macro printContents();

	proc sql noprint;
		*Get all the libraries that you want;
	  	select cats(libname,".",memname) into : ds separated by " " 
		from dictionary.tables
		where libname = upcase('SASHELP') and upcase(memname) in ("CLASS" "BASEBALL");
	quit;

	*Get the number of tables to loop.;
	%let no_of_tables=%sysfunc(countw(&ds," "));

	*Loop the list;
	%do _i = 1 %to &no_of_tables;
		%let ds_name=%scan(&ds,&_i, %str( ));
		PROC CONTENTS DATA=&ds_name; 
		RUN; 
	%end;
%mend printContents;

%printContents();

Maybe this? 

Haydn
Quartz | Level 8
Thanks heffo, it did the trick.

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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.

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
  • 5 replies
  • 2670 views
  • 3 likes
  • 3 in conversation