Previous Page | Next Page

Using SAS Tables

Determining Attributes of SAS Tables and Columns in SCL Programs

SCL provides features for determining characteristics (or attributes) of the SAS table or columns with which a program is working. For example, one approach is to open a table, determine how many columns are in the table, and then set up a program loop that executes once for each column. The loop can query the attributes of each column. To do this, the program needs to determine how many columns are in the SAS table, as well as the name, type, length, format, informat, label, and position of each column.


Querying Attributes of SAS Tables

SAS tables have a variety of numeric and character attributes associated with them. These attributes can provide some basic information to your SCL program. For example, to determine the number of columns in an existing SAS table, use the NVARS argument with the ATTRN function. For a list of other table attributes and how to retrieve them, see ATTRC and ATTRN.


Querying Attributes of SAS Table Columns

Columns in a SAS table also have several attributes that your program may need to query. Here is a list of column attributes and the SCL functions that you can use to retrieve those attributes:

name VARNAME function
number VARNUM function
data type VARTYPE function
length VARLEN function
label VARLABLE function
format VARFMT function
informat VARINFMT function.


Defining New Columns

After determining the name, type, length, label, format, and informat of each column, you can add a new column that has these attributes to the column list for a new SAS table. To do this, first use the OPEN function with the N argument (for NEW mode), and then use the NEWVAR function.

CAUTION:
Your program should check to see whether the SAS table exists before opening it in NEW mode.

When used with the N argument (for NEW mode), the OPEN function replaces an existing SAS table that has the same name. If you do not want to delete an existing SAS table by opening it in NEW mode, then use the EXIST function to confirm that the table does not exist before using OPEN to create a new SAS table.   [cautionend]

Previous Page | Next Page | Top of Page