Previous Page | Next Page

Functions and CALL Routines

LIBNAME Function



Assigns or deassigns a libref for a SAS library.
Category: SAS File I/O
See: LIBNAME Function under Windows OpenVMS

Syntax
Arguments
Details
Basic Information about Return Codes
When LIBNAME Has One Argument
When LIBNAME Has Two Arguments
When LIBNAME Has Three or Four Arguments
Examples
Example 1: Assigning a Libref
Example 2: Deassigning a Libref
Example 3: Compressing a Library
See Also

Syntax

LIBNAME(libref<,SAS-library<,engine<,options>>>)


Arguments

libref

is a character constant, variable, or expression that specifies the libref that is assigned to a SAS library.

Tip: The maximum length of libref is eight characters.
SAS-library

is a character constant, variable, or expression that specifies the physical name of the SAS library that is associated with the libref. Specify this name as required by the host operating environment. This argument can be null.

engine

is a character constant, variable, or expression that specifies the engine that is used to access SAS files opened in the data library. If you are specifying a SAS/SHARE server, then the value of engine should be REMOTE. This argument can be null.

options

is a character constant, variable, or expression that specifies one or more valid options for the specified engine, delimited with blanks. This argument can be null.


Details


Basic Information about Return Codes

The LIBNAME function assigns or deassigns a libref from a SAS library. When you use the LIBNAME function with two or more arguments, SAS attempts to assign the libref. When you use one argument, SAS attempts to deassign the libref. Return codes are generated depending on the value of the arguments that are used in the LIBNAME function and whether the libref is assigned.

When assigning a libref, the return code will be 0 if the libref is successfully assigned. If the return code is nonzero and the SYSMSG function returns a warning message or a note, then the assignment was successful. If the SYSMSG function returns an error, then the assignment was unsuccessful.

If a library is already assigned, and you attempt to assign a different name to the library, the libref is assigned, the LIBNAME function returns a nonzero return code, and the SYSMSG function returns a note.


When LIBNAME Has One Argument

When LIBNAME has one argument, the following rules apply:


When LIBNAME Has Two Arguments

When LIBNAME has two arguments, the following rules apply:


When LIBNAME Has Three or Four Arguments

Note:   In the DATA step, a character constant that consists of two consecutive quotation marks without any intervening spaces is interpreted as a single space, not as a string with a length of 0. To specify a string with a length of 0, use the TRIMN Function.   [cautionend]

Operating Environment Information:   Some systems allow a SAS-library value of '' (a space between the single quotation marks) to assign a libref to the current directory. Other systems disassociate the libref from the SAS library when the SAS-library value contains only blanks. The behavior of LIBNAME when a single space is specified for SAS-library is dependent on your operating environment.

Under some operating environments, you can assign librefs by using system commands that are outside the SAS session.  [cautionend]


Examples


Example 1: Assigning a Libref

This example attempts to assign the libref NEW to the SAS library MYLIB. If an error or warning occurs, the message is written to the SAS log. Note that in a macro statement you do not enclose character strings in quotation marks.

%if (%sysfunc(libname(new,MYLIB))) %then
  %put %sysfunc(sysmsg());


Example 2: Deassigning a Libref

This example deassigns the libref NEW that was previously associated with the data library MYLIB in the preceding example. If an error or warning occurs, the message is written to the SAS log. In a macro statement, you do not enclose character strings in quotation marks.

%if (%sysfunc(libname(new))) %then
  %put %sysfunc(sysmsg());


Example 3: Compressing a Library

This example assigns the libref NEW to the MYLIB data library and uses the COMPRESS option to compress the library. This example uses the default SAS engine. In a DATA step, you enclose character strings in quotation marks.

data test;
   rc=libname('new','MYLIB',,'compress=yes');
run;


See Also

Functions:

LIBREF Function

SYSMSG Function

Previous Page | Next Page | Top of Page