DATA Step, Macro, Functions and more

Wild Cards in Proc Contents?

Reply
Contributor
Posts: 30

Wild Cards in Proc Contents?

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

Trusted Advisor
Posts: 1,115

Re: Wild Cards in Proc Contents?

Try this:

data _null_;
set sashelp.vtable;
where libname='SASHELP' & memname=:'C';
call execute(cats('proc contents data=',libname,'.',memname,'; run;'));
run;
Contributor
Posts: 30

Re: Wild Cards in Proc Contents?

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
Contributor
Posts: 55

Re: Wild Cards in Proc Contents?

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;
Super User
Posts: 17,836

Re: Wild Cards in Proc Contents?

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. 

 

 

 

Trusted Advisor
Posts: 1,115

Re: Wild Cards in 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

  • 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."

 

 

 

Super User
Posts: 17,836

Re: Wild Cards in Proc Contents?

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.
Ask a Question
Discussion stats
  • 6 replies
  • 323 views
  • 1 like
  • 4 in conversation