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 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1938 views
  • 3 likes
  • 3 in conversation