Preparation For Test

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

SAS Consulting, Department of Statistics

SAS FAQ: What is a LIBNAME statement used for?


SAS version 6.12 and 7

If you are not sure what a SAS data set is, read this first. What is a SAS data set?

A LIBNAME statement is used when you want SAS to store/retrieve SAS data sets from a directory other
than the default, saswork, directory. This is the method used to save SAS data sets between SAS
sessions.

The LIBNAME statement assigns an alias, libref, to a specific directory . The libref is used in subsequent
programs in place of the directory name. Once a data set is stored in the desired directory, the associated
libref must be used to retieve the data set. Without a libref SAS would look in the default, saswork,
directory for the data set.

Background:
SAS stores data sets in the saswork directory unless another directory is requested by the program. The
saswork directory is erased at the end of each SAS session. For this reason, data sets stored in saswork
are only available during the current SAS session. Data sets stored in saswork are commonly referred to
as "temporary". Data sets stored in any other directory are refered to as "permanent."

In summary:
 The default storage location for SAS data sets is the saswork directory.
 Data sets stored in the saswork directory are erased at the end of the SAS session.
 Libname statements assign an alias, libref, to a directory.
 Once Assigned, librefs are used to indicate the directory location for saving or accessing SAS data
sets.

Here are some examples.


Program
Description
Statements
No LIBNAME statement and no libref. The data set "class1" will be stored is the
data class1; saswork directory. It will be erased at the end of the SAS session, so it is a
"temporary" SAS data set.
libname mylib The LIBNAME statement defines the libref, "mylib", as the "research" subdirectory.
'research'; The SAS data set "exp1" will be written in the "research" subdirectory, because the
data mylib.exp1; libref "mylib" was used on the data statement.
The dot inside the parenthesis on the LIBNAME statement means "current working
libname inlib '.';
directory". The SAS data set "chem" will be written in the "current working
data inlib.chem;
directory", because the libref, "inlib", was used on the data statement.
libname lib1
'c:\mysas'; Data set "a" will be a copy of "exp1". "a" will be written in the saswork directory,
data a; set data set "exp1" will be read from c:\mysas.
lib1.exp;

You might also like