Assigning a Libref to Several Directories (Concatenating Directories)


Introduction to Concatenating Directories

You can use the LIBNAME statement to assign librefs and engines to one or more directories, including the Work directory.

If you have SAS data sets located in multiple directories, you can treat these directories as a single SAS data library by specifying a single libref and concatenating the directory locations, as in the following example:

 libname income ('/u/2002/revenue', '/u/2002/costs'); 

This statement indicates that the two directories, /u/2002/revenue and /u/2002/costs , are to be treated as a single SAS data library.

If you have already assigned librefs to your SAS data libraries, you can use these librefs to indicate that you want to concatenate the data libraries, as in this example:

 libname income ('/u/2002/corpsale', '/u/2002/retail');   libname costs ('/u/2002/salaries', '/u/2002/expenses');   libname profits (income, costs, '/u/2002/capgain'); 

This statement indicates that the five directories, /u/2002/corpsale , /u/2002/retail , /u/2002/salaries , /u/2002/expenses , and /u/2002/capgain , are to be treated as a single SAS data library.

How SAS Accesses Concatenated Data Libraries

When you concatenate SAS data libraries, SAS uses a protocol for accessing the libraries, which depends on whether you are accessing the libraries for read, write, or update. (A protocol is a set of rules.)

SAS uses the protocol shown in the following sections to determine which directory is accessed. (The protocol illustrated by these examples applies to all SAS statements and procedures that access SAS files, such as the DATA, UPDATE, and MODIFY statements in the DATA step, and the SQL and APPEND procedures.)

Accessing Files for Input and Update

When a SAS data set is accessed for input or update, the first SAS data set that is found by that name is the one that is accessed. For example, if you submit the following statements and the data set Old.Species exists in both directories, the one in the mysasdir directory is the one that is printed:

 libname old ('mysasdir','saslib');   proc print data=old.species;   run; 

The same would be true if you opened Old.Species for update with the FSEDIT procedure.

Accessing Files for Output

If the data set is accessed for output, it is always written to the first directory, provided that the directory exists. If the directory does not exist, an error message is displayed. For example, if you submit the following statements, SAS writes the Old.Species data set to the first directory ( mysasdir ) and replaces any existing data set with the same name:

 libname old ('mysasdir','saslib');   data old.species;   x=1;   y=2;   run; 

If a copy of the Old.Species data set exists in the second directory, it is not replaced .

Accessing Data Sets with the Same Name

If you use the DATA and SET statements to access data sets with the same name, the DATA statement uses the output rules and the SET statement uses the input rules. For example, suppose you submit the following statements and Test.Species originally exists only in the second directory, mysasdir :

 libname test ('sas','mysasdir');   data test.species;   set test.species;   if value1='y' then      value2=3;   run; 

The DATA statement opens Test.Species for output according to the output rules; that is, SAS opens a data set in the first of the concatenated libraries ( sas ). The SET statement opens the existing Test.Species data set in the second ( mysasdir ) directory, according to the input rules. Therefore, the original Test.Species data set is not updated. After the data step executes, two Test.Species data sets exist, one in each directory.




SAS 9.1 Companion for UNIX Environments
SAS 9.1 Companion For Unix Enivronments
ISBN: 1590472101
EAN: 2147483647
Year: 2004
Pages: 185
Authors: SAS Institute

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net