Chapter Contents

Previous

Next

Library Names


Physical Names and Logical Names (Librefs)

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

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

The logical name, or libref, is the way you identify a group of files to SAS. A libref is a temporary name that you associate with the physical name of the SAS data library during each SAS job or session.

Librefs that you specify remain in effect until the SAS session ends, unless you create them in the SAS New Library window and check the "Enable at startup" box when you create the library. The New Library window is available in your Toolbar.


Assigning Librefs

Once the libref is assigned, you can read, create, or update files in a data library. You can also access files without using a libref. See "Accessing Permanent SAS Files Without a Libref." 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 may set limitations. See the LIBREF function in SAS Language Reference: Dictionary for more information.

Librefs can be assigned with the following:

Operating Environment Information:   The rules for assigning and using librefs differ across operating environments. See the SAS documentation for your operating environment for more specific information.  [cautionend]To assign a library name to your SAS data library using the physical name, you assign a libref to the library, followed by the physical location, enclosed in single quotation marks.

If running in batch mode, the library must exist before you can allocate or assign it. In interactive mode, you may be allowed to create it if it does not already exist.

Syntax for Assigning a Libref
Operating Environment Examples
DOS, Windows
libname mylibref 'c:\root\mystuff\sasstuff\work' ;
UNIX
libname mylibref '/u/mystuff/sastuff/work';
UNIX System Services under OS/390
libname mylibref '/mystuff/sastuff/work';
CMS
libname mylibref '< filetype> filemode |* ';

OS/390 Open Edition
libname mylibref 'my.data_library';

OS/390
libname mylibref 'userid.mystuff.sastuff.work';
VAX/ALPHA
libname mylibref 'filename filetype filemode';



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 data library. When using operating environment commands to assign librefs to a SAS data library, the association may 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 data library.

libname annual 'SAS-data-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 data 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 later in this section.

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


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.