0% found this document useful (0 votes)
89 views1 page

Understanding SAS LIBNAME Statements

A LIBNAME statement assigns an alias called a libref to a directory other than the default saswork directory. This allows SAS data sets to be stored in a permanent location between SAS sessions rather than being erased. The libref is then used in place of the directory name on subsequent data steps to indicate where to save or retrieve SAS data sets. Without a LIBNAME statement, data sets would be stored temporarily in the saswork directory and erased at the end of the session.

Uploaded by

shahinaA
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views1 page

Understanding SAS LIBNAME Statements

A LIBNAME statement assigns an alias called a libref to a directory other than the default saswork directory. This allows SAS data sets to be stored in a permanent location between SAS sessions rather than being erased. The libref is then used in place of the directory name on subsequent data steps to indicate where to save or retrieve SAS data sets. Without a LIBNAME statement, data sets would be stored temporarily in the saswork directory and erased at the end of the session.

Uploaded by

shahinaA
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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 [Link];
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.
[Link];

You might also like