SAS Companion for UNIX Environments |
If you want to read or write to a
permanent
SAS file, you can refer to the SAS file in one of two ways:
- refer to the data file directly by using its pathname
in the appropriate statements (such as DATA, SET, MERGE, UPDATE, OUTPUT, and
PROC).
- assign a libref to the SAS data library (directory)
that contains the data file and use the libref as the first level of a two-level
file name.
A libref is a nickname that you can use to refer to the
data library during the SAS session or job. You will probably want to use
a libref when:
- the data file pathname is long and must be specified
several times within a program
- the pathname might change. If the pathname changes,
you need to change only the statement assigning the libref, not every reference
to the file.
- your application will be used on other platforms.
Using librefs makes it easier to port an application to other operating environments.
- you need to concatenate libraries. See
Assigning a Libref to Several Directories (Concatenating Directories) for more information.
You can assign a libref with the LIBNAME statement or through the New Library
window in the Explorer. To open the New Library window, select
File |
|
New |
|
Library |
You
can also use an environment variable as the libref.
After you have defined a libref, you can use the libref
in one of two ways to access a permanent SAS data library:
- as the first level of a two-level SAS file
name:
where libref is the first-level name
referring to the directory where the file is stored, and member-name specifies the name of the file being read or created.
- as the
value of the USER= option. (See USER Data Library for details.)
For example, these SAS statements access the data file
FINAL.DATA
in the library in the the directory
/users/myid/mydir
:
libname sales '/users/myid/mydir';
data sales.final;
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.