BookmarkSubscribeRSS Feed
endomorph-21
Calcite | Level 5

Hello. I would like to find a function/statement that extracts all field names of a table. Then I would like to iterate it over all existing tables within a library and list them in a dataset like this

 

TABLE | FIELD

table 1 | field 1

table 1 | field 2

           ...

table 1 | field m

           ...

table 2 | field 1

table 2 | field 2

            ...

            ...

table n | field m

2 REPLIES 2
Tom
Super User Tom
Super User

Just use PROC CONTENTS.

So if your libref is LIBREF then this code will make a dataset named WANT with one observation per variable per dataset (member).

PROC CONTENTS data=libref._all_ out=WANT; run;

Add NOPRINT option to the PROC statement if you don't need to see the contents printed. 

ballardw
Super User
Proc SQL;
    create table want as
    select libname, memname, name
    from dictionary.columns
    where libname='WORK' and memtype='DATA'
    ;
quit;

or

data otherwant;
   set sashelp.vcolumn;
   where libname='WORK' and memtype='DATA';
run;

SAS keeps all that metadata in special data views in the SASHELP library. You can look at them with any tool you like. The Proc SQL treats them as members of a special set of members in the DICTIONARY (note that is not really a library  as more than 8 characters) that has different members that contain information about data variables (columns), data sets, libraries, external files, macros, title statements and more.

SAS Innovate 2025: Call for Content

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!

Submit your idea!

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
  • 2 replies
  • 2085 views
  • 2 likes
  • 3 in conversation