SAS Libraries

A SAS library is a collection of one or more SAS files, including SAS data sets, that are referenced and stored as a unit. In a directory-based operating environment, a SAS library is a group of SAS files that are stored in the same directory. In z/OS, a SAS library is a group of SAS files that are stored in an operating environment file.

Assigning Librefs

Often the first step in setting up your SAS session is to define the libraries. You can use programming statements to assign library names.
To reference a permanent SAS file:
  1. Assign a name (libref) to the SAS library in which the file is stored.
  2. Use the libref as the first part of the two-level name (libref.filename) to reference the file within the library.
Figure 3.1 Defining Libraries
Defining Libraries
A logical name (libref) can be assigned to a SAS library using the LIBNAME statement. You can include the LIBNAME statement with any SAS program so that the SAS library is assigned each time the program is submitted. Using the user interface, you can set up LIBNAME statements to be automatically assigned when SAS starts.
Syntax, LIBNAME statement:
LIBNAME libref engine 'SAS-data-library';
  • libref is 1 to 8 characters long, begins with a letter or underscore, and contains only letters, numbers, or underscores.
  • engine is the name of a library engine that is supported in your operating environment.
    Note: For SASĀ®9, the default engine is V9, which works in all operating environments.
  • SAS-data-library is the name of a SAS library in which SAS data files are stored. The specification of the physical name of the library differs by operating environment.
The LIBNAME statement below assigns the libref Cert to the SAS library C:UsersStudent1Cert in the Windows environment. When the default engine is used, you do not have to specify it in the LIBNAME statement.
libname cert 'C:UsersStudent1Cert';
The table below gives examples of physical names for SAS libraries in various operating environments.
Table 3.1 Sample Physical Names for SAS Libraries
Environment
Sample Physical Name
Windows
c:fitnessdata
UNIX
/users/april/fitness/sasdata
z/OS)
april.fitness.sasdata
Tip
You can use multiple LIBNAME statements to assign as many librefs as needed.

Verifying Librefs

After assigning a libref, it is a good idea to check the log to verify that the libref has been assigned successfully.
Log 3.1 Output for Cert Libref
1    libname cert 'C:UsersStudent1Cert';
NOTE: Libref CERT was successfully assigned as follows:
      Engine:        V9
      Physical Name: C:UsersStudent1Cert

How Long Librefs Remain in Effect

The LIBNAME statement is global, which means that the librefs remain in effect until changed or canceled, or until the SAS session ends.
By default, the LIBNAME statement assigns the libref for the current SAS session only. Each time you begin a SAS session, you must assign a libref to each permanent SAS library that contains files that you want to access in that session. (Remember that Work is the default libref for a temporary SAS library.)

Specifying Two-Level Names

After you assign a libref, you specify it as the first element in the two-level name for a SAS file.
In order for the PRINT procedure to read cert.admit, you specify the two-level name of the file as follows:
proc print data=cert.admit; 
run;

Referencing Third-Party Data

You can use the LIBNAME statement to reference not only SAS files but also files that were created with other software products, such as database management systems.
A SAS engine is a set of internal instructions that SAS uses for writing to and reading from files in a SAS library or a third-party database. SAS can read or write these files by using the appropriate engine for that file type. For some file types, you need to tell SAS which engine to use. For others, SAS automatically chooses the appropriate engine.
An example of an engine that accesses third-party data is the XLSX engine, which processes Microsoft Excel workbooks.

Accessing Stored Data

If your site licenses SAS/ACCESS software, you can use the LIBNAME statement to access data that is stored in a database management system (DBMS) file. The types of data you can access depend on your operating environment and on which SAS/ACCESS products you have licensed. For more information about SAS/ACCESS engines, see the SAS documentation for your DBMS.
Last updated: August 23, 2018
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.138.69.157