LIBNAME Statement

To use a SAS data set, you
  1. assign a libref (library reference name) to reference the SAS library where the data set is stored
  2. use the libref as the first part of the two-level data set name.

You can store the LIBNAME statement with any SAS program to reference the SAS library automatically when you submit the program.


General form, basic LIBNAME statement:
LIBNAME libref 'SAS-data-library';

where

  • libref is 1 to 8 characters long; begins with a letter or underscore; and contains only letters, numbers, or underscores.

  • SAS-data-library is the name of the SAS library where the file is stored. The specification of the physical name of the library differs by operating system and machine.


The LIBNAME statement below assigns the libref Clinic to the SAS data library D:\Users\Qtr\Reports in the Windows environment.
     libname clinic 'd:\users\qtr\reports';

After you assign a libref, you specify it as the first element in the two-level name for a SAS file. For example, to specify that the PRINT procedure read Clinic.Therapy, you specify the two-level name of the file as follows:

     proc print data=clinic.therapy;
     run;

How Long Librefs Remain in Effect

The LIBNAME statement is global, which means that its settings remain in effect until you modify them, cancel them, or end your SAS session.

Therefore, the LIBNAME statement assigns the libref for the current SAS session only. You must assign a libref each time you begin a SAS session in order to access SAS files stored in a permanent SAS data library. (Remember that Work is the default libref for a temporary SAS data library.)


librefs assigned and deassigned








Copyright © 2002 SAS Institute Inc., Cary, NC, USA. All rights reserved.

Terms of Use & Legal Information | Privacy Statement