Understanding SAS Data Libraries |
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:
directly specify the operating environment's physical name for the location of the SAS data library. The physical name must conform to the naming conventions of your operating environment, and it must be in single quotation marks. For example, in the SAS windowing environment, the following DATA statement creates a data set named MYFILE:
data 'c:\my documents\sasfiles\myfile';
assign a SAS libref (library reference), which is a SAS name that is temporarily associated with the physical location name of the SAS data library.
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' ; |
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'; |
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.
Copyright © 2012 by SAS Institute Inc., Cary, NC, USA. All rights reserved.