BookmarkSubscribeRSS Feed
ArpitSharma
Fluorite | Level 6

Hello,

 

I want to do a proc contents on many datasets(NOT ALL) within the same library.

 

I want something like this. Proc contents on all datasets in sashelp library starting with "c"

The below code definitely does not work.

 

proc contents data = sashelp.c : ;

run; 

 

How can I do this?

Thanks

6 REPLIES 6
FreelanceReinh
Jade | Level 19

Try this:

data _null_;
set sashelp.vtable;
where libname='SASHELP' & memname=:'C';
call execute(cats('proc contents data=',libname,'.',memname,'; run;'));
run;
ArpitSharma
Fluorite | Level 6
Thank You for your suggestion. Yes I get what you are trying to say but I am sorry I did not put exactly what I wanted. In the question when I say "sashelp" what I actually mean is ANY library. Not every library will have a vtable within it. Over here you are suggesting something very specific for sashelp.vtable , which is not exactly what I meant. I hope now I am explaining it more precisely. Sorry for misleading info above. Regards
JoshB
Quartz | Level 8

SASHELP.VTABLE exists always, as far as I know.

 

It might help your understanding of what this suggestion gives you if you view this table. It's essentially

 

PROC PRINT DATA=SASHELP.VTABLE;RUN;

Either way, you can modify the where statement to choose any assigned library you want. You could also get rid of the library='SASHELP' piece of the where statement altogether to see all tables in all libraries you have assigned. e.g.

data _null_;
  set sashelp.vtable;
  where memname=:'C';
  call execute(cats('proc contents data=',libname,'.',memname,'; run;'));
run;
Reeza
Super User

What output do you want from proc contents? It may be worth grabbing the info from SASHELP.VCOLUMN/VTABLE rather than pull from proc contents. 

 

 

 

FreelanceReinh
Jade | Level 19

Hello, @ArpitSharma,

 

It appears that I should have commented my suggestion a little more. Thanks to @JoshB for stepping in during the night (in my time zone).

 

Yes, the SET statement reading SASHELP.VTABLE is the constant part of the suggested data _null_ step. It was just coincidence that library SASHELP occurred in your example, too.

 

SASHELP.VTABLE is one of more than 30 SQL views on the so called DICTIONARY tables. These, in turn, are "special read-only PROC SQL tables or views [which] retrieve information about all the SAS libraries, SAS data sets, SAS system options, and external files that are associated with the current SAS session" (online documentation).


So, there is a lot of information, namely metadata, available through these views. As @Reeza suggested, the information you are looking for could most likely be retrieved directly from the DICTIONARY tables. This would be particularly convenient if you want to store or process those metadata.


However, if you just want to quickly look through selected PROC CONTENTS outputs on the screen, my suggested code should work well for you. Please note how flexible the WHERE condition is: You can filter by any combination of the 40+ variables in SASHELP.VTABLE, using operators and SAS functions to specify your selection criteria.

 

Example: If you are interested in the PROC CONTENTS outputs of all datasets

  • excluding views
  • in all libraries whose librefs start with "PROJ"
  • which have been modified within the previous month
  • whose names contain the substring "LAB"
  • whose dataset labels do not contain the substring "2015"
  • excluding small files <256 KB, unless they have at least 500 observations or more than 10 variables
  • ...

you could easily adapt the WHERE clause to match exactly these selection requirements (using variables
MEMTYPE, LIBNAME, MODATE, MEMNAME, MEMLABEL, FILESIZE, NOBS, NVAR, etc. of SASHELP.VTABLE).

 

As you can see, this goes far beyond what could be achieved with "wild cards in proc contents."

 

 

 

Reeza
Super User
Proc contents and sashelp.vtable use the same source of information. If you have a server, certain information is not includes in either proc contents or the dictionary tables.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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
  • 6 replies
  • 1129 views
  • 1 like
  • 4 in conversation