SAS LIBRARY - HOW TO CREATE A LIBRARY | HOW TO DELETE A LIBRARY

What is a Library -

It is a collection of one or more SAS files that are recognized by SAS and stored as a unit. You reference a SAS library by a logical name called a libref.

At the beginning of each SAS session, SAS automatically creates at least one library that which is Work, Work is the temporary library, As soon as session terminated work library also get destroyed.

All SAS data sets have a two-level name that consists of the library name and the data set name.

When a data set is in the Work library, then it is not required to include the library name when you reference it.

Example -

Data EX; RUN;

Data Work.EX; RUN;

Both above datasets are same pointing to EX in work library.

Creating a Library

LIBNAME - 

SAS library can be created using LIBNAME statement. The LIBNAME statement associates the name of the library, or libref, with the physical location of the library. 

Libname - Datahark

Libname-Creating library


In SAS Studio, It is even more easier to create a Library without writing any code - You can create a new SAS library by opening the New Library window from the Libraries section of the navigation pane in SAS Studio.

SAS LIBRARY 2

SAS LIBRARY


Clearing a Library - 

you can delete a library reference by using the clear statement, the 

Syntax  - 

libname libref clear;

Example - 
LIBNAME Datahark Clear;

LIBNAME Datahark Clear;
LIBNAME Datahark Clear;

Clear Library

How to get list of sas datasets in a library?

This can be done with the help of PROC CONTENTS

Example - If we need to get the list of all dataset from SASHELP library -

proc contents data=SASHELP._all_ out=Libraries memtype=data noprint;
run;

Proc SQL;
select DISTINCT MEMNAME from Libraries;
quit;


This will Print the list of all all dataset from SASHELP library in result window.
 

Post a Comment

0 Comments