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: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

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