how to create a library in sas

How to Create a Library in SAS

By Joshua Smith
AD

Creating a library in SAS involves planning, programming, and managing sets of SAS code, data, andmacro statements. A SAS library serves as a central repository, simplifying data management and facilitating code sharing and reuse. Let's delve into the process of creating and managing a SAS library, ensuring your data and codebase are organized and accessible.

BeforeJumping into the specifics, ensure you have the necessary permissions to create and manage libraries in your SAS environment. SAS libraries are typically stored in directories, and the ability to create directories and set folder permissions is crucial.

Creating a SAS Library

A SAS library can contain datasets, catalogs (which store various SAS entities such as formats, informats, and customized report templates), and custom programs. To create a SAS library, you'll first need to define a directory on your file system and then inform SAS about this new library.

AD
Build your free resource library & share your freebies
Build your free resource library & share your freebies
How to Start a STEM Library
How to Start a STEM Library
How to Create a Meaningful School Library Orientation
How to Create a Meaningful School Library Orientation

Here's how you can do this using the DATA step and the LIBNAME statement:

Creating a Library using DATA Step

The LIBNAME statement is used to assign a SAS library name to a directory. You can use the DATA step to create a SAS library with a single line of code:

Library Makerspace Ideas
Library Makerspace Ideas
Easy School Library Orientation Plan (No Stress Back to School)
Easy School Library Orientation Plan (No Stress Back to School)
&libname mylib 'path myocardialirectory';

In this example, 'mylib' is the SAS library name, and 'path myocardialirectory' is the directory location on your file system. Replace these with your chosen library name and directory path.

Once you've defined your library, you can use it to store SAS datasets and other SAS entities. For instance, to create an empty dataset in your library, you can use the following code:

AD
Data mylib.empty; Run;

The above code will create an empty dataset named 'empty' in your 'mylib' library.

Creating a Library using PROC FCMPProcedure

You can also create a SAS library using PROC FCM (File Description Viewer) procedure. This option provides a workaround when you don't have the necessary permissions to create a library using the LIBNAME statement.

To create a library using PROC FCM, follow these steps:

AD
  1. Open SAS and select the 'SAS Files' option from the 'Tools' menu.
  2. In the File Description Viewer window, navigate to the directory where you want to create your library.
  3. Right-click in the window and select 'New Library' from the drop-down menu.
  4. Enter the desired library name and click 'OK'.

PROC FCM creates a new folder with the specified name at the chosen location, and this folder can now be used as a SAS library.

Setting Library Options

SAS allows you to set options for a library to specify how files are accessed or created in that library. You can set library options using the LIBNAME statement or the OPTIONS statement in the configuration file.

Here are a few commonly used library options:

AD
  • JOURNAL: Enables journal support for the library. Journal files are useful for source code management and debugging.
  • PROC: Enables procedural language support for the library.
  • TEXT: Enables text file support for the library.

To apply these options to our 'mylib' library, you can use the following LIBNAME statement:

&libname mylib 'path myocardialirectory' options=(JOURNAL TEXT);

This statement enables journal and text file support for the 'mylib' library.

In a well-organized SAS environment, each team member should have their own library. This encourages code and data sharing while maintaining individual responsibility. Regularly backing up your libraries ensures your work is protected and accessible, even when switching to a new machine or updating your SAS version.

AD