Displaying the Structure of a Table

Overview

Sometimes you want to look at the structure (the columns and column attributes) of a table that you created or of a table that was created by someone else. When you create a table, the CREATE TABLE statement writes a message to the SAS log, which indicates the number of rows and columns in the table that was created. However, that message does not contain information about column attributes.
If you are working with an existing table that contains rows of data, you can use a PROC SQL query to generate a report that shows all of the columns in a table. However, the report does not list the column attributes, and a PROC SQL query does not generate output for an empty table.
To display a list of columns and column attributes for one or more tables in the SAS log, regardless of whether the tables contain rows of data, you can use the DESCRIBE TABLE statement in PROC SQL.
General form, DESCRIBE TABLE statement:
DESCRIBE TABLE table-name-1<, ... table-name-n>;
Here is an explanation of the syntax:
table-name
specifies the table to be described as one of the following:
  • a one-level name
  • a two-level libref.table name
  • a physical pathname that is enclosed in single quotation marks.
The DESCRIBE TABLE statement writes a CREATE TABLE statement that includes column definitions to the SAS log for the specified table, regardless of how the table was originally created. For example, if the DESCRIBE TABLE statement specifies a table that was created with the DATA step, a CREATE TABLE statement is still displayed.
Note: The DESCRIBE TABLE statement also displays information about any indexes that are defined on a table. You can learn more about using the DESCRIBE TABLE statement to display information about indexes in Creating and Managing Indexes Using PROC SQL.
Tip
As an alternative to the DESCRIBE TABLE statement, you can use other SAS procedures, like PROC CONTENTS, to list a table's columns and column attributes. PROC CONTENTS generates a report instead of writing a message to the SAS log, as the DESCRIBE TABLE statement does.

Example

Earlier in this chapter, the empty table Work.Discount was created by using the CREATE TABLE statement and column specifications shown below:
proc sql;
   create table work.discount 
          (Destination char(3),
          BeginDate num format=date9.,
          EndDate num format=date9.,
          Discount num);
The following DESCRIBE TABLE statement writes a CREATE TABLE statement to the SAS log for the table Work.Discount:
proc sql;
   describe table work.discount;
Note: For more information about the BUFSIZE= option, see Using the BUFSIZE= Option.
Table 5.7 SAS Log
NOTE: SQL table WORK.DISCOUNT was created like:
create table WORK.DISCOUNT( bufsize=4096 )
            (            
            Destination char(3),
            BeginDate num format=DATE9.,
            EndDate num format=DATE9.,
            Discount num
            )
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.135.247.181