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-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2982 views
  • 2 likes
  • 3 in conversation