Open a SAS Data Set

You must open a SAS data set before you can access the data. There are three ways to open a SAS data set:

  • To read from an existing data set, submit the USE statement, which opens a data set for input. The general form of the USE statement is as follows:

    USE SAS-data-set <VAR operand> <WHERE(expression)> ;

    You can use the FIND, INDEX, LIST, and READ statements after the data set is open.

  • To read and write to an existing data set, use the EDIT statement. The general form of the EDIT statement is as follows:

    EDIT SAS-data-set <VAR operand> <WHERE(expression)> ;

    This statement enables you to use both the reading statements (LIST, READ, INDEX, and FIND) and the writing statements (REPLACE, APPEND, DELETE, and PURGE).

  • To create a new data set, use the CREATE statement, which opens a new data set for both output and input. The general form of the CREATE statement is as follows:

    CREATE SAS-data-set <VAR operand> ;

    CREATE SAS-data-set FROM matrix-name <[COLNAME=column-name
    ROWNAME=row-name]> ;

    Use the APPEND statement to place data into the newly created data set. If you do not use the APPEND statement, the new data set will not contain any observations.

See the section Process Data by Using the WHERE Clause for details about using the WHERE clause; see the section Select Variables with the VAR Clause for details about using the VAR clause.

Specify a data set name as the first operand to the USE, EDIT, and CREATE statements. This name can have either one or two levels. If it is a two-level name, the first level refers to the name of the SAS data library, and the second level refers to the data set name. If the libref is Work, the data set is stored in a temporary directory. All data in the Work library are deleted at the end of the SAS session.

You can use the LIBNAME statement to assign a libref that refers to a permanent directory, as described in SAS Language Reference: Concepts. If you specify only a single name, then a default libref is used. The default libref is Sasuser if Sasuser is defined or Work otherwise. You can reset the default libref by using the RESET DEFLIB statement, as shown in the following statements:

libname mydir "C:\Users\userid\Documents\My SAS Files";
reset deflib=mydir;

If you run these statements, one-level names are read from and written to the mydir library.