Previous Page | Next Page

Understanding SAS Data Libraries

Accessing a SAS Data Library


Telling SAS Where the SAS Data Library Is Located

No matter which operating environment you are using, to access a SAS data library, you must tell SAS where it is. To do so, you can do one of the following:


Assigning a Libref

After you assign a libref to the location of a SAS data library, then in your SAS program you can reference files in the library by using the libref instead of using the long physical name that the operating environment uses. The libref is a SAS name that is temporarily associated with the physical location of the SAS data library. There are several ways to assign a libref:

A common method for assigning a libref is to use the LIBNAME statement to associate a name with a SAS data library. Here is the simplest form of the LIBNAME statement:

LIBNAME libref 'SAS-data-library' ;

where

libref

is a shortcut name to associate with the SAS data library. This name must conform to the rules for SAS names. A libref cannot exceed eight characters.

Operating Environment Information:   Under the z/OS operating environment, the libref must also conform to the rules for operating environment names.  [cautionend]

Think of the libref as an abbreviation for the operating environment's name for the library. Because the libref endures only for the duration of the SAS session, you do not have to use the same libref for a particular SAS data library each time you use SAS.

Operating Environment Information:   Under the CMS operating environment, the libref typically specifies the filetype of all files in the library. In this case, you must always use the same libref for a SAS data library because the filetype does not change.  [cautionend]

SAS-data-library

is the physical name for the SAS data library. The physical name is the name that is recognized by your operating environment. Enclose the physical name in single or double quotation marks.

Operating Environment Information:   Here are examples of the LIBNAME statement for different operating environments. For more examples, see the SAS documentation for your operating environment.

Windows

libname mydata 'c:\my documents\sasfiles';
UNIX

libname mydata '/u/myid/sasfiles';
z/OS

libname mydata 'edc.company.sasfiles';
  [cautionend]

When you assign a libref with the LIBNAME statement, SAS writes a note to the SAS log confirming the assignment. This note also includes the operating environment's physical name for the SAS data library.


Using Librefs for Temporary and Permanent Libraries

When a libref is assigned to a SAS data library, you can use the libref throughout the SAS session to access the SAS files that are stored in that library or to create new files.

When you start a SAS session, SAS automatically assigns the libref WORK to a special SAS data library. Normally, the files in the WORK library are temporary files; that is, usually SAS initializes the WORK library when you begin a SAS session, and deletes all files in the WORK library when you end the session. Therefore, the WORK library is a useful place to store SAS files that you do not need to save for a subsequent SAS session. The automatic deletion of the WORK library files at the end of the session prevents you from wasting disk space.

Files that are stored in any SAS data library other than the WORK library are usually permanent files; that is, they endure from one SAS session to the next. Store SAS files in a permanent library if you plan to use them in multiple SAS sessions.

Previous Page | Next Page | Top of Page