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
Try this:
data _null_;
set sashelp.vtable;
where libname='SASHELP' & memname=:'C';
call execute(cats('proc contents data=',libname,'.',memname,'; run;'));
run;
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;
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.
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
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."
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!
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.