SAS 9.1 Companion For Unix Enivronments

Techniques for Referring to a SAS File

If you want to read or write to a permanent SAS file, you can refer to the SAS file in one of two ways:

What is a Libref?

A libref is a nickname that you can use to refer to the data library during a SAS session or job. You will probably want to use a libref when:

Librefs can be stored in the SAS registry. See "Customizing Your SAS Registry Files" on page 16 for more information.

Assigning Librefs

You can use any of the following methods to assign a SAS libref:

A libref assignment remains in effect for the duration of the SAS job, session, or process unless you either clear the libref or use the same libref in another LIBNAME statement or LIBNAME function.

If you assign a libref from a SAS process, that libref is valid only within that SAS process. If you clear a libref from within a SAS process, that libref is not cleared from other SAS processes.

Using the LIBNAME Statement

The LIBNAME statement identifies a SAS data library to SAS, associates an engine with the library, enables you to specify options for the library, and assigns a libref to it. For details about LIBNAME statement syntax, see "LIBNAME Statement" on page 301.

Using the LIBNAME Function

The LIBNAME function takes the same arguments and options as the LIBNAME statement. For more information about the LIBNAME function, see "LIBNAME Function" on page 250.

Using the LIBASSIGN Command

Perform the following steps to assign a libref using the LIBASSIGN command:

  1. Issue the LIBASSIGN command in the command window. The New Library dialog box opens.

  2. Specify the libref in the Name field.

  3. Specify an engine for the libref in the Engine field by selecting the default engine or another engine from the drop-down menu. Depending on the engine that you specify, the fields in the Library Information area might change.

  4. Click the Enable at startup box to assign this libref when you invoke SAS.

  5. Specify the necessary information for the desired SAS data library in the Library Information area. Depending on the engine selected, there may or may not be a Path field available for input.

  6. Specify LIBNAME options in the Options field. These options can be specific to your host or engine, including options that are specific to a SAS engine that accesses another software vendor's relational database system.

  7. Click OK .

Using the LIBNAME Window

Perform the following steps to assign a libref from the LIBNAME window

  1. Issue the LIBNAME command in the command window. The LIBNAME window opens.

  2. From the File pull-down menu, select New . The New Library dialog box opens.

  3. Fill in the fields in the New Library dialog box, described in "Using the LIBASSIGN Command" on page 112.

  4. Click OK .

Using the SAS Explorer Window

Perform the following steps to assign a libref from the SAS Explorer window:

  1. From the File pull-down menu, select New when the Libraries node in the tree structure is active. The New dialog box opens.

  2. Select Library , and then click OK . The New Library dialog box opens.

  3. Fill in the fields in the New Library dialog box, described in "Using the LIBASSIGN Command" on page 112.

  4. Click OK .

Permanently Assigning a Libref

You might want to save a libref so that it is valid between SAS sessions. You can assign a libref permanently by using one of the following methods:

Accessing a Permanent SAS Data Library using a Libref

After you have defined a libref, you can use the libref in one of two ways to access a permanent SAS data library:

For example, these SAS statements access the data file Final.sas7bdat in the Sales library that is stored in the /users/myid/mydir directory:

libname sales '/users/myid/mydir'; data sales.final;

Категории