Chapter Contents

Previous

Next
LIBNAME

LIBNAME



Associates or disassociates a SAS data library with a libref (a shortcut name); clears one or all librefs; lists the characteristics of a SAS data library; concatenates SAS data libraries; implicitly concatenates SAS catalogs.

Valid: Anywhere
Category: Data Access
See Also: LIBNAME, SAS/ACCESS


Syntax
Options
Engine-Host-Options
Details
[1]Associating a Libref with a SAS Data Library
[2]Disassociating a libref from a SAS Data Library
[3]Writing SAS Data Library Attributes to the SAS Log
[4]Concatenating SAS Data Libraries
[5]Implicitly Concatenating SAS Catalogs
Rules for Library Concatenation
Comparisons
Examples
Example 1: Assigning and Using a Libref
Example 2: Logically Concatenating SAS Data Libraries
Example 3: Implicitly Concatenating SAS Catalogs
Example 4: Storing Data Sets with One-Level Names Permanently
See Also

Syntax

[1]LIBNAME libref <engine> 'SAS-data-library'
< options > <engine/host-options>;
[2]LIBNAME libref CLEAR | _ALL_ CLEAR;
[3]LIBNAME libref LIST | _ALL_ LIST;
[4][5]LIBNAME libref <engine> (library-specification-1 <. . . library-specification-n>)
< options > ;

libref
is a shortcut name or a "nickname" for the aggregate storage location where your SAS files are stored. It is any SAS name when you are assigning a new libref. When you are disassociating a libref from a SAS data library or when listing attributes, specify a libref that was previously assigned.
Tip: The association between a libref and a SAS data library lasts only for the duration of the SAS session or until you change it or discontinue it with another LIBNAME statement.

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

Operating Environment Information:   For details on specifying the physical names of files, see the SAS documentation for your operating environment.  [cautionend]

In some operating environments, you can use an operating environment command, the LIBNAME statement, or the LIBNAME function to associate the libref with the SAS data library. In others, you must use an operating environment command. See the SAS documentation for your operating environment for more information.

library-specification
is two or more SAS data libraries, specified by physical names, previously-assigned librefs, or a combination of the two. Separate each specification with either a blank or a comma and enclose the entire list in parentheses.

'SAS-data-library'
the physical name of a SAS data library, enclosed in quotation marks.

libref
is the name of a previously-assigned libref.

Restriction: When concatenating libraries, you cannot specify options that are specific to an engine or an operating environment.
Featured in: Logically Concatenating SAS Data Libraries
See Also: Rules for Library Concatenation

engine
is an engine name.
Tip: Generally, SAS automatically determines the appropriate engine to use for accessing the files in the library. If you want to create a new library with an engine other than the default engine, you can override the automatic selection.
See: For a list of valid engines, see the SAS documentation for your operating environment. For background information about engines, see SAS Language Reference: Concepts.

CLEAR
disassociates one or more currently assigned librefs.
Tip: Specify libref to disassociate a single libref. Specify _ALL_ to disassociate all currently assigned librefs.

_ALL_
specifies that the CLEAR or LIST argument applies to all currently-assigned librefs.

LIST
writes the attributes of one or more SAS data libraries to the SAS log.
Tip: Specify libref to list the attributes of a single SAS data library. Specify _ALL_ to list the attributes of all SAS data libraries that have librefs in your current session.


Options

ACCESS=READONLY|TEMP
READONLY assigns a read-only attribute to an entire SAS data library. SAS will not allow you to open a data set in the library in order to update information or write new information.
TEMP indicates that the SAS data library be treated as a scratch library. That is, the system will not consume CPU cycles to ensure that the files in a TEMP library do not become corrupted.
Tip: Use ACCESS=TEMP to save resources only when the data are recoverable.

Operating Environment Information:   Some operating environments support LIBNAME statement options that have similar functions to the ACCESS= option. See the SAS documentation for your operating environment.  [cautionend]

OUTREP=default-format
specifies the default format for the SAS data library that is specified. New data sets that are stored in this SAS data library are written in this format. Existing data sets that are written to the library are given the new format. Values for OUTREP= are
MVS

CMS

VSE

VAX_VMS

ALPHA_VMS

ALPHA_OSF

SOLARIS

HP_UX

RS_6000_AIX

WINDOWS

OS2

MAC

REPEMPTY=YES|NO
controls replacement of like-named temporary or permanent SAS data sets when the new one is empty.
YES specifies that a new empty data set with a given name replaces an existing data set with the same name. This is the default.
Interaction: When REPEMPTY=YES and REPLACE=NO, then the data set is not replaced.
NO specifies that a new empty data set with a given name does not replace an existing data set with the same name.
Tip: Use REPEMPTY=NO to prevent the following syntax error from replacing the existing data set MYLIB.B with the new empty data set MYLIB.B that is created by mistake:
libname libref SAS-data-library REPEMPTY=NO;
data mylib.a set mylib.b;
Tip: For both the convenience of replacing existing data sets with new ones that contain data and the protection of not overwriting existing data sets with new empty ones that are created by accident, set REPLACE=YES and REPEMPTY=NO.
Comparison: For an individual data set, the REPEMPTY= data set option overrides the setting of the REPEMPTY= option in the LIBNAME statement.
See Also: REPEMPTY=

TRANTAB=translation-table
specifies the translation table to use for character conversions. When any data set in a format foreign to the host is written to the specified SAS data library, SAS uses the specified translation table.
Interaction: A translation table that is specified with the TRANTAB= data set option for a specific data set overrides the translation table that is specified with the TRANTAB= option in the LIBNAME statement for an entire library.

Operating Environment Information:   For a list of valid specifications, see the SAS documentation for your operating environment.  [cautionend]


Engine-Host-Options

engine-host-options
are one or more options listed in the general form keyword=value.

Operating Environment Information:   For a list of valid specifications, see the SAS documentation for your operating environment.  [cautionend]
Restriction: When concatenating libraries, you cannot specify options that are specific to an engine or an operating environment.


Details

[1]Associating a Libref with a SAS Data Library

The association between a libref and a SAS data library lasts only for the duration of the SAS session or until you change it or discontinue it with another LIBNAME statement. The simplest form of the LIBNAME statement specifies only a libref and the physical name of a SAS data library:


Syntax

LIBNAME libref 'SAS-data-library';

See Assigning and Using a Libref.

An engine specification is usually not necessary. If the situation is ambiguous, SAS uses the setting of the ENGINE= system option to determine the default engine. If all data sets in the library are associated with a single engine, SAS uses that engine as the default. In either situation, you can override the default by specifying another engine with the ENGINE= option:


Syntax

LIBNAME libref engine 'SAS-data-library'
<options > <engine/host-options>;

Operating Environment Information:   Using the LIBNAME statement requires host-specific information. See the SAS documentation for your operating environment before using this statement.   [cautionend]

[2]Disassociating a libref from a SAS Data Library

To disassociate a libref from a SAS data library, use a LIBNAME statement, specifying the libref and the CLEAR option. You can clear a single, specified libref or all current librefs.


Syntax

LIBNAME libref CLEAR | _ALL_ CLEAR;

[3]Writing SAS Data Library Attributes to the SAS Log

Use a LIBNAME statement to write the attributes of one or more SAS data libraries to the SAS log. Specify libref to list the attributes of one SAS data library; use _ALL_ to list the attributes of all SAS data libraries that have been assigned librefs in your current SAS session.


Syntax

LIBNAME libref LIST | _ALL_ LIST;

[4]Concatenating SAS Data Libraries

When you logically concatenate two or more SAS data libraries, you can reference them all with one libref. You can specify a library with its physical pathname or its previously assigned libref.


Syntax

LIBNAME libref <engine> (library-specification-1 <. . . library-specification-n>)
< options > ;

In the same LIBNAME statement you can use any combination of specifications: librefs, physical pathnames, or a combination of librefs and pathnames. See Logically Concatenating SAS Data Libraries.

[5]Implicitly Concatenating SAS Catalogs

When you logically concatenate two or more SAS data libraries, you also implicitly concatenate the SAS catalogs that have the same name. For example, if three SAS data libraries each contain a catalog named CATALOG1, then when you concatenate them, you implicitly create a catalog concatenation for the catalogs that have the same name. See Implicitly Concatenating SAS Catalogs.


Syntax

LIBNAME libref <engine> (library-specification-1 <. . . library-specification-n>)
< options > ;

Rules for Library Concatenation

After you create a library concatenation, you can specify the libref in any context that accepts a simple (nonconcatenated) libref. These rules determine how SAS files (that is, members of SAS libraries) are located among the concatenated libraries:

  1. When a SAS file is opened for input or update, the concatenated libraries are searched and the first occurrence of the specified file is used.

  2. When a SAS file is opened for output, it is created in the first library that is listed in the concatenation.

    Note:   A new SAS file is created in the first library even if there is a file with the same name in another part of the concatenation.  [cautionend]

  3. When you delete or rename a SAS file, only the first occurrence of the file is affected.

  4. Any time a list of SAS files is displayed, only one occurrence of a file name is shown.

    Note:   Even if the name occurs multiple times in the concatenation, only the first occurrence is shown.  [cautionend]

  5. A SAS file that is logically connected to another file (such as an index to a data set) is listed only if the parent file resides in that same library. For example, if library ONE contains A.DATA, and library TWO contains A.DATA and A.INDEX, only A.DATA from library ONE is listed. (See rule 4.)

  6. If any library in the concatenation is sequential, then all of the libraries are treated as sequential.

  7. The attributes of the first library that is specified determine the attributes of the concatenation. For example, if the first SAS data library that is listed is "read only", then the entire concatenated library is "read only".

  8. If you specify any options or engines, they apply only to the libraries that you specified with the complete physical name, not to any library that you specified with a libref.

  9. If you alter a libref after it has been assigned in a concatenation, it will not affect the concatenation.


Comparisons


Examples

Example 1: Assigning and Using a Libref

This example assigns the libref SALES to an aggregate storage location that is specified in quotation marks as a physical pathname. The DATA step creates SALES.QUARTER1 and stores it in that location. The PROC PRINT step references it by its two-level name, SALES.QUARTER1.

   libname sales 'SAS-data-library';

   data sales.quarter1;
      infile 'your-input-file;  
      input salesrep $20. +6 jansales febsales 
            marsales;
   run;

   proc print data=sales.quarter1;
   run;

Example 2: Logically Concatenating SAS Data Libraries


Example 3: Implicitly Concatenating SAS Catalogs

This example concatenates three SAS data libraries by specifying the physical filename of each and assigns the libref ALLMINE to the concatenated libraries:

   libname allmine ('path-1' 'path-2'
                   'path-3');
 

If each library contains a SAS catalog named MYCAT, then using ALLMINE.MYCAT as a libref.catref provides access to the catalog entries that are stored in all three catalogs named MYCAT. To logically concatenate SAS catalogs with different names, see CATNAME.

Example 4: Storing Data Sets with One-Level Names Permanently

If you want the convenience of specifying only a one-level name for permanent, not temporary, SAS files, use the USER= system option. This example stores data set QUARTER1 permanently without using a LIBNAME statement first to assign a libref to a storage location:

   options user='SAS-data-library';

   data quarter1;
      infile 'your-input-file;  
      input salesrep $20. +6 jansales febsales 
            marsales;
   run;

   proc print data=quarter1;
   run;

See Also

Statements:
CATNAME for a discussion of explicitly concatenating SAS catalogs
FILENAME
LIBNAME, SAS/ACCESS
System Option:
USER=


Chapter Contents

Previous

Next

Top of Page

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