Functions and CALL Routines |
Category: | SAS File I/O |
See: | LIBNAME Function under Windows OpenVMS |
Syntax |
LIBNAME(libref<,SAS-library<,engine<,options>>>) |
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. |
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.
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.
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 |
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, the following rules apply:
If the libref is not assigned, a nonzero return code is returned and the SYSMSG function returns a warning message.
If the libref is successfully assigned, a 0 return code is returned and the SYSMSG function returns a blank value.
When LIBNAME has two arguments, the following rules apply:
If the second argument is NULL, all blanks, or zero length, SAS attempts to deassign the libref.
If the second argument is not NULL, not all blanks, and not zero length, SAS attempts to assign the specified path (the second argument) to the libref.
If the libref is not assigned, a nonzero return code is returned and the SYSMSG function returns an error message.
If the libref is successfully assigned, a 0 return code is returned and the SYSMSG function returns a blank value.
If the second argument is NULL, all blanks, or zero length, the results depend on your operating environment.
If the second argument is NULL and the libref is not already assigned, then a nonzero return code is returned and the SYSMSG function returns an error message.
If the second argument is NULL and the libref has already been assigned, then LIBNAME returns a value of 0 and the SYSMSG function returns a blank value.
If at least one of the previous conditions is not met, then SAS attempts to assign the specified path (second argument) to the libref.
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.
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.
Examples |
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());
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());
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 |
|
Copyright © 2011 by SAS Institute Inc., Cary, NC, USA. All rights reserved.