In SAS tips & tricks #2 we looked at retrieving metadata within a datastep using the VARxx functions. Here we look at how the SAS dictionary tables can be used to retrieve SAS metadata.
If you’ve ever wondered how to determine which variables are present in a dataset, which titles have been set, what format is associated with a particular variable or which ODS destinations have been setup, the dictionary tables could be what you are looking for.
The dictionary tables are a collection of automatically available, read only, tables accessible via PROC SQL. For example, the following SQL clause would create a dataset containing variable level metaedata for the SASHELP.FLAGS dataset, which would include, amongst other things, a list of all the variables present in the dataset, their lengths, formats, informats and more.
PROC SQL ; CREATE TABLE flag_var_meta AS SELECT * FROM dictionary.columns WHERE libname = "SASHELP" AND memname ="FLAGS" ; QUIT;
Whereas the following code would create a dataset containing all TITLES and FOOTNOTES currently set within the session.
PROC SQL ; CREATETABLE title_meta AS SELECT * FROM dictionary.titles; QUIT;
It’s easy to see how this information can be used to automate subsequent programming steps.
More information on the SAS dictionary tables is available in the SAS (R) online documentation: