/*** TIP 00404 ***/

/*******************************************************/
/*** Dictionary Tables                               ***/
/***                                                 ***/
/***  dictionary.catalogs  or sashelp.vcatalg        ***/
/***            .columns             .vcolumn        ***/
/***            .extfiles            .vextfl         ***/
/***            .indexes             .vindex         ***/
/***            .macros              .vmacro         ***/
/***            .members             .vmember        ***/
/***            .options             .voption        ***/
/***            .tables              .vtable         ***/
/***            .titles              .vtitle         ***/
/***            .views               .vview          ***/
/***                                                 ***/
/***  An Example of what you can find in the         ***/
/***     Dictionary Tables or SASHELP V views        ***/
/***                                                 ***/
/***  Create a TEST Dataset in WORK Library to       ***/
/***   Illustrate                                    ***/
/***                                                 ***/
/*******************************************************/

 options obs=20 linesize=255 pagesize=59 nocenter;
 %let _mylib_ = WORK ; /*** Use WORK LIBRARY for Demo Purposes ***/

 /*** direct all output to external file for review ***/
 /*** you will need to know where this gets created ***/
 /*** or direct it to specific directory that you know ***/

 proc printto file="dictionary_tables.txt" new; run;


 /*** create a format table just so there is a catalog entry in WORK
      library to illustrate ***/
 proc format;
  value fmtz   0   = "0"
             1-9   = "1"
            10-25  = "2"
            26-high= "3"
            other  = "?"
 run;

 /*** delete view or table TEST just to make sure it does not exist ***/
 /*** there will be warning message issued depending on which one   ***/
 /*** does not exist or both do not exist                           ***/

 proc sql; drop view  test;
           drop table test;
 quit;


 /*** Generate Test SAS Dataset in work library ***/
 data test (label="Dictionary_Table.sas" );
   retain note "Test";
   label note  = "Dictionary Tables";
   label today = "Today's Date";
   label i     = "Counter";
   label x     = "Squared";
   label z     = "Dummy"  ;
   format note $20. i z2. x 5. z fmtz3. today datetime. ;
   today = today();
   do i = 1 to 10;
      x = i**2;
      z = x+i;
      output;
   end;
 run;


 /*** create an INDEX in Test dataset for column Z
      so there is an entry
      for INDEX Dictionary Table for demonstration Purpose ***/
    proc sql; create INDEX Z on Test(Z); quit;

 /*** Now Illustrate what each Dictionary Table Contains
      for MetaData about your SAS Session ***/

 Title1 "Catalogs in &_mylib_";
 proc sql;
      select *
      from dictionary.catalogs
      where upcase(libname) = "&_mylib_";
 quit;

 Title1 "Columns in &_mylib_";
 proc sql;
      select *
      from dictionary.columns
      where upcase(libname) = "&_mylib_";
 quit;

 Title1 "Indexes in &_mylib_";
 proc sql;
      select *
      from dictionary.indexes
      where upcase(libname) = "&_mylib_";
 quit;

 Title1 "Members in &_mylib_";
 proc sql;
      select *
      from dictionary.members
      where upcase(libname) = "&_mylib_";
 quit;

 Title1 "Tables in &_mylib_";
 proc sql;
      select *
      from dictionary.tables
      where upcase(libname) = "&_mylib_";
 quit;

 Title1 "Extfiles in &_mylib_";
 proc sql;
      select *
      from dictionary.extfiles;
 quit;

 Title1 "Macros in &_mylib_ - GLOBAL only";
 proc sql;
      select *
      from dictionary.macros
      /*** select only GLOBAL Macro Variables ***/
      where scope = "GLOBAL" ;
 quit;

 Title1 "Options in &_mylib_ starting with S";
 proc sql;
      select *
      from dictionary.options
      /*** select only options starting with letter "S" ***/
      where substr(optname,1,1) = "S" ;
 quit;

 Title1 "Titles in &_mylib_";
 proc sql;
      select *
      from dictionary.titles ;
 quit;

 Title1 "Views in &_mylib_";
 proc sql;
      select *
      from dictionary.views ;
 quit;

 /*** re-direct all output to default ***/
 proc printto; run;

 /*** end of SAS program ***/

/*** end of tip 00404 ***/