Library Concatenation

Definition of Library Concatenation

Concatenation is the logical combining of two or more libraries. Concatenation enables you to access the SAS data sets in several libraries with one libref.
You can concatenate two or more libraries by specifying their librefs or physical names in the LIBNAME statement or function.
Physical names must be enclosed in single or double quotation marks in a LIBNAME statement. Otherwise, SAS looks for a previously assigned libref with the same name.
In the following examples, summer, winter, spring, fall, and annual are previously defined librefs:
libname annual (summer winter spring fall);

libname annual ('path1' 'path2'  'path3');

libname annual ('path' winter spring fall);

libname total (annual 'path');

How SAS Concatenates Library Members

When there are members of the same name in more than one library, the first occurrence of the member is used for input and update processes. Output always goes to the first library.
This example contains three SAS libraries, and each library contains two SAS data files:
LIB1
APPLES and PEARS
LIB2
APPLES and ORANGES
LIB3
ORANGES and PLUMS
The LIBNAME statement concatenates LIB1, LIB2, and LIB3:
libname fruit (lib1 lib2 lib3);
The concatenated library FRUIT has the following members:
  • APPLES
  • PEARS
  • ORANGES
  • PLUMS
Note: Output always goes to the first library. For example, the following statement writes to the first library in the concatenation, LIB1:
data fruit.oranges;
Note that in this example, if the file APPLES in LIB1 was different from the file APPLES in LIB2, and if an update to APPLES was specified, it is updated only in LIB1 because that is the first occurrence of the member APPLES.
For complete documentation on library concatenation, see the LIBNAME Statement in SAS Statements: Reference.
Operating Environment Information: For more information about how specific operating environments handle concatenation, see the SAS documentation for your operating environment.

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:
  • If you specify any options or an engine, the options apply only to the libraries that you specified with the physical name, not to any library that you specified with a libref.
  • 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.
  • When a SAS file is opened for output, it is created in the first library that is listed in the concatenation.
  • When you delete or rename a SAS file, only the first occurrence of the file is affected.
  • Any time a list of SAS files is displayed, only one occurrence of a filename is shown, even if the name occurs multiple times in the concatenation. For example, if library ONE contains A.DATA and library TWO contains A.DATA, only A.DATA from library ONE is listed because it is the first occurrence of the filename.
    In addition, a SAS file that is logically connected to another file (such as an index to a data file) is listed only if the parent file is the first (or only) occurrence of the filename. 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. A.DATA and A.INDEX from library TWO are not listed.
  • If any library in the concatenation is sequential, then the concatenated library is considered sequential by applications that require random access. For example, the DATASETS procedure cannot process sequential libraries, and therefore cannot process a concatenated library that contains one or more sequential libraries.
  • The attributes of the first library that is specified determine the attributes of the concatenation. For example, if the first SAS library that is listed is “read only,” then the entire concatenated library is “read only.”
  • Once a libref has been assigned in a concatenation, any changes made to the libref does not affect the concatenation.
  • Changing a data set name to an existing name in the concatenation will fail.