Previous Page | Next Page

SAS Libraries

Library Names

Physical Names and Logical Names (Librefs)

Before you can use a SAS library, you must tell SAS where it is. SAS recognizes SAS libraries based on either operating environment naming conventions or SAS naming conventions. There are two ways to define SAS libraries.

The physical location name of the SAS library is a name that identifies your SAS files to the operating environment. The physical location name must conform to the naming conventions of your operating environment. The physical location name fully identifies the directory, or operating environment data set that contains the SAS library.

The logical name, or libref, is the way you identify a group of files to SAS. A libref is a name that you associate with the physical location of the SAS library.

Assigning Librefs

Librefs can be assigned using the following methods:

Once the libref is assigned, you can read, create, or update files in a SAS library. A libref is valid only for the current SAS session, unless it is assigned using the New Library window with the Enable at startup box checked.

A libref can have a maximum length of eight characters. You can use the LIBREF function to verify that a libref has been assigned. Librefs can be referenced repeatedly within a SAS session. SAS does not limit the number of librefs you can assign during a session; however, your operating environment or site might set limitations. If you are running in batch mode, the library must exist before you can allocate or assign it. In interactive mode, you might be allowed to create it if it does not already exist.

Operating Environment Information:   Here are examples of the LIBNAME statement for different operating environments. The rules for assigning and using librefs differ across operating environments. See the SAS documentation for your operating environment for specific information.  [cautionend]

Syntax for Assigning a Libref
Operating Environment Examples
DOS, Windows
libname mylibref 'c:\root\mystuff\sasstuff\work';
libname mylibref '/u/mystuff/sastuff/work';
libname mylibref '';
libname mylibref '/mystuff/sastuff/work';
OpenVMS for Integrity servers
libname mylibref 'filename filetype filemode';

You can also access files without using a libref. See Accessing Permanent SAS Files without a Libref.

Associating and Clearing Logical Names (Librefs) with the LIBNAME Statement

You can assign or clear a physical name with a libref using the LIBNAME statement or the LIBNAME function, which are described in the SAS Language Reference: Dictionary.

Operating Environment Information:   For some operating environments, you can use operating environment commands to associate a libref with a SAS library. When using operating environment commands to assign librefs to a SAS library, the association might persist beyond the SAS session in which the libref was created. For some operating environments you can use only the LIBNAME statement or function. See the SAS documentation for your operating environment for more information on assigning librefs.  [cautionend]

The most common form of the LIBNAME statement is used in this example to associate the libref ANNUAL with the physical name of the SAS library.

libname annual 'SAS-library';

If you use the LIBNAME statement to assign the libref, SAS clears (deassigns) the libref automatically at the end of each SAS session. If you want to clear the libref ANNUAL before the end of the session, you can issue the following form of the LIBNAME statement:

libname annual clear;

SAS also provides a New Library window to assign or clear librefs and SAS Explorer to view, add, or delete SAS libraries. You can select the New Library or the SAS Explorer icon from the Toolbar.

Reserved Librefs

SAS reserves a few names for special uses. You should not use SASHELP, SASUSER or SASWORK as librefs, except as intended. The purpose and content of these libraries are discussed in Permanent and Temporary Libraries.

Operating Environment Information:   There are other librefs reserved for SAS under some operating environments. In addition, your operating environment might have reserved certain words that cannot be used as librefs. See the SAS documentation for your operating environment for more information.  [cautionend]

Accessing Remote SAS Libraries on SAS/CONNECT, SAS/SHARE, and WebDAV Servers

Remote Library Access for SAS/CONNECT and SAS/SHARE

You can use a LIBNAME statement to read, write, and update server (remote) data as if it were stored on the client's disk. SAS processes the data in client memory, which gets overwritten in subsequent client requests for server data.

The LIBNAME statement can be used to access SAS data sets across computers that have different architectures. The LIBNAME statement also provides read-only access to some SAS catalog entry types across computers that have different architectures.

The LIBNAME statement provides access to remote server data by associating a SAS library reference (libref) with a permanent SAS library.


The SAS/CONNECT client creates a LIBNAME statement to access a server library that is located on a SAS/CONNECT server. The client creates the new libref, REPORTS.

signon rempc;
libname reports 'd:\prod\reports' server=rempc;

The SAS/CONNECT client signs on to the SAS/CONNECT server named REMPC. A server library is assigned to the client session. The value for SERVER= is the same as the server session ID that is used in the SIGNON statement.

For more information about SAS/CONNECT, see SAS/CONNECT User's Guide.

SAS/SHARE Example:

The SAS/SHARE client uses a LIBNAME statement to access a server library via the existing libref, SALES, which was pre-defined at the SAS/SHARE server for client access.

libname sales server=server1; 

For more information about SAS/SHARE, see SAS/SHARE User's Guide.

Remote Library Access for WebDAV Servers

WebDAV (Web Distributed Authoring and Versioning) is a protocol that enhances the HTTP protocol. It provides a standard infrastructure for collaborative authoring across the Internet. WebDAV enables you to edit Web documents, stores versions for later retrieval, and provides a locking mechanism to prevent overwriting. SAS supports the WebDAV protocol under the UNIX and Windows operating environments.

You use a LIBNAME statement to access WebDAV servers, as shown in the following example:

libname davdata v9 ""
        webdav user="mydir" pw="12345";

When you access files on a WebDAV server, SAS pulls the file from the server to your local disk for processing. The files are temporarily stored in the SAS WORK directory, unless you use the LOCALCACHE= option in the LIBNAME statement, which specifies a different directory for temporary storage. When you finish updating the file, SAS pushes the file back to the WebDAV server for storage and removes the file from the local disk.

For more information, see the LIBNAME Statement for WebDAV Server Access in SAS Language Reference: Dictionary.

Previous Page | Next Page | Top of Page