Accessing Libraries through a Server

Introduction

The information in this section is primarily directed to applications developers. However, server administrators and end users might also find it of interest. For more information about programming techniques and adjusting SAS system option values to improve the performance of your client/server applications, see Tuning Tips for Applications That Use SAS/SHARE Software.

Using the LIBNAME Statement

To access a SAS library or an external DBMS through a SAS/SHARE server, you must use the REMOTE engine to define a libref for the library. In a LIBNAME statement, specify the libref, which identifies the library or the DBMS, and the SAS/SHARE server that you'll use to access that library or DBMS.
In the following example, the engine name REMOTE, which is usually specified between the libref and the pathname, is omitted because it is implied by the SERVER= option.
libname invoice '/dept/acct/data/invoice' server=share1;
If the library is predefined to the server by a server administrator, you can omit the pathname and use only the libref, which is defined for the library in the server SAS session, to identify the library. Omitting the pathname protects your application if the pathname for the library has changed.
In the following example, the REMOTE engine and the server assume that the libref (invdata), which you defined for your SAS session, is the same libref that is defined by the server administrator in the server SAS session.
libname invdata server=share1;
If the library is predefined to the server but you want to define a libref that is different from the one that is defined in the server SAS session, use the SLIBREF= option in the LIBNAME statement to specify a newly defined server libref, as shown in the following example. However, if a server runs with the option NOALLOC in effect, all libraries that are accessed through that server must be predefined by the server administrator.
libname invoice server=share1 slibref=invdata;
For details about the LIBNAME statement syntax, see Remote Library Services.

Using Macros to Generate a LIBNAME Statement

Hard coding the server name in a LIBNAME statement can be a problem if the server administrator shifts one server's traffic to another server, thereby invalidating the server name.
You can avoid this problem by using a SAS macro to generate the required LIBNAME statement. If you use a macro in your end-user application, you can change the name of the server in one place, even though multiple applications access data through that server. Using macros improves maintenance of your SAS programs.
SAS/SHARE provides macros for generating LIBNAME statements. To associate a server name with a SAS library, register the library in the table that is maintained by the server administrator. Instead of specifying a LIBNAME statement to access the library, use the LIBDEF macro. When you invoke the LIBDEF macro, it searches the table of registered data libraries for the specified library. When the LIBDEF macro finds the library, it uses the associated server name and the specified libref to construct the LIBNAME statement. Before the first invocation of the LIBDEF macro in a SAS execution, you must invoke the SHRMACS macro with the keyword USER.
%shrmacs(user);
The SHRMACS macro generates and compiles other SAS/SHARE macros and builds the SAS server-alias and library-alias tables in which server libraries are registered.
To invoke the LIBDEF macro, specify the libref and the optional server library. Here is an example:
%libdef(datalib<,SAS-data-library>);
For more information about using the LIBDEF macro, see Generating a LIBNAME Statement By Using the LIBDEF Macro. For complete details about macro syntax, see SAS/SHARE Macros. Contact your server administrator for information about how the macros and tables are implemented and how they are used at your site.