Previous Page | Next Page

Using SAS Files

Referring to SAS Files by Using Librefs in UNIX Environments


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 an alias that you can use to refer to the library during a SAS session or job. You will probably want to use a libref when one of the following is true:

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

Assigning Librefs


Methods for 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 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 library to SAS, associates an engine with the library, enables you to specify options for the library, and assigns a libref to it. For information about LIBNAME statement syntax, see LIBNAME Statement: UNIX.


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 SAS Language Reference: Dictionary.


Use the DMLIBASSIGN Command

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

  1. Issue the DMLIBASSIGN 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 menu. Depending on the engine that you select, the fields in the Library Information area might change.

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

  5. Specify the necessary information for the SAS library in the Library Information area. Depending on the engine that you select, there might 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.


Use 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 menu, select New.

    The New Library dialog box opens.

  3. Complete the fields in the New Library dialog box as described in Use the DMLIBASSIGN Command.

  4. Click OK.


Use the SAS Explorer Window

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

  1. From the File 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. Complete the fields in the New Library dialog box as described in Use the DMLIBASSIGN Command.

  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 Library by Using a Libref

After you have defined a libref, you can use the libref in one of two ways to access a permanent SAS 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;

Previous Page | Next Page | Top of Page