In-Database Deployment Package for DB2

Prerequisites

SAS Foundation and the SAS/ACCESS Interface to DB2 must be installed before you install and configure the in-database deployment package for DB2.
The SAS Scoring Accelerator for DB2 requires a certain version of the DB2 client and server environment. For more information, see http://www.sas.com/technologies/analytics/datamining/scoring_acceleration/#section=5.

Overview of the In-Database Deployment Package for DB2

This section describes how to install and configure the in-database deployment package for DB2 (SAS Formats Library for DB2 2.1 and SAS Embedded Process 9.33).
The in-database deployment package for DB2 must be installed and configured before you can perform the following tasks:
  • Use the %INDB2_PUBLISH_FORMATS format publishing macro to create or publish the SAS_PUT( ) function and to create or publish user-defined formats as format functions inside the database.
  • Use the %INDB2_PUBLISH_MODEL scoring publishing macro to create scoring model functions inside the database.
The format and scoring publishing macros are included in SAS/ACCESS Interface to DB2. For more information about using the format and scoring publishing macros, see the SAS In-Database Products: User's Guide.
The in-database deployment package for DB2 contains the SAS formats library and the precompiled binary files for two additional publishing macros. Starting in December 2011, the package also contains the SAS Embedded Process.
The SAS formats library is a run-time library that is installed on your DB2 system so that the SAS scoring model functions and the SAS_PUT( ) function created in DB2 can access the routines within the run-time library. The SAS formats library contains the formats that are supplied by SAS.
The two publishing macros, %INDB2_PUBLISH_COMPILEUDF and %INDB2_PUBLISH_DELETEUDF, register utility functions in the database. The utility functions are called by the format and scoring publishing macros. You must run these two macros before you run the format and scoring publishing macros.
The SAS Embedded Process is a SAS server process that runs within DB2 to read and write data. The SAS Embedded Process contains macros, run-time libraries, and other software that is installed on your DB2 system so that the SAS scoring files created in DB2 can access the routines within the SAS Embedded Process’s run-time libraries.

Function Publishing Process in DB2

To publish scoring model functions and the SAS_PUT( ) function on a DB2 server, the publishing macros perform the following tasks:
  • Create and transfer the files to the DB2 environment.
  • Compile those source files into object files using the appropriate compiler for that system.
  • Link with the SAS formats library.
After that, the publishing macros register the format and scoring model functions in DB2 with those object files. If an existing format or scoring model function is replaced, the publishing macros remove the obsolete object file upon successful compilation and publication of the new format or scoring model functions.
The publishing macros use a SAS FILENAME SFTP statement to transfer the format or scoring source files to the DB2 server. An SFTP statement offers a secure method of user validation and data transfer. The SAS FILENAME SFTP statement dynamically launches an SFTP or PSFTP executable, which creates an SSH client process that creates a secure connection to an OpenSSH Server. All conversation across this connection is encrypted, from user authentication to the data transfers.
Currently, only the OpenSSH client and server on UNIX that supports protocol level SSH-2 and the PUTTY client on WINDOWS are supported. For more information about setting up the SSH software to enable the SAS SFTP to work, please see Setting Up SSH Client Software in UNIX and Windows Environments for Use with the SFTP Access Method in SAS 9.2 and SAS 9.3, located at http://support.sas.com/techsup/technote/ts800.pdf.
Note: This process is valid only when using publishing formats and scoring functions. It is not applicable to the SAS Embedded Process. If you use the SAS Embedded Process, the scoring publishing macro creates the scoring files and uses the SAS/ACCESS Interface to DB2 to insert the scoring files into a model table.

DB2 Installation and Configuration Steps

  1. If you are upgrading from or reinstalling a previous version, follow the instructions in Upgrading from or Reinstalling a Previous Version.
  2. Verify that you can use PSFTP from Windows to UNIX without being prompted for a password or cache.
    To do this, enter the following commands from the PSFTP prompt, where userid is the user ID that you want to log on as and machinename is the machine to which you want to log on.
    psftp> open userid@machinename
    psftp> ls
  3. Install the SAS formats library, the binary files for the SAS_COMPILEUDF and SAS_DELETEUDF functions, and the SAS Embedded Process.
  4. Run the %INDB2_PUBLISH_COMPILEUDF macro to create the SAS_COMPILEUDF function.
  5. Run the %INDB2_PUBLISH_DELETEUDF macro to create the SAS_DELETEUDF function.
    For more information, see Running the %INDB2_PUBLISH_DELETEUDF Macro.
  6. If you plan to use SAS Model Manager with the SAS Scoring Accelerator for in-database scoring, perform the additional configuration tasks provided in Configurations for SAS Model Manager.

Upgrading from or Reinstalling a Previous Version

Overview of Upgrading from or Reinstalling a Previous Version

You can upgrade from or reinstall a previous version of the SAS Formats Library and binary files, the SAS Embedded Process, or both. See the following topics:

Upgrading from or Reinstalling the SAS Formats Library, Binary Files, and the SAS Embedded Process

To upgrade from or reinstall a previous version of the SAS Formats Library, binary files, and the SAS Embedded Process, follow these steps.
Note: These steps also apply if you want to upgrade from or reinstall only the SAS Formats Library and binary files. If you want to upgrade from or reinstall only the SAS Embedded Process, see Upgrading from or Reinstalling the SAS Embedded Process.
  1. Drop the SAS_COMPILEUDF and SAS_DELETEUDF functions by running the %INDB2_PUBLISH_COMPILEUDF and %INDB2_PUBLISH_DELETEUDF macros with ACTION=DROP.
    Here is an example.
    %let indconn = user=abcd password=xxxx database=indbdb server=indbsvr;
    %indb2pc;
    %indb2_publish_compileudf(action=drop, db2path=/db2/9.3/sqllib, 
       compiler_path=/usr/vac/bin);
    %indb2pd;
    %indb2_publish_deleteudf(action=drop);
  2. Confirm that the SAS_COMPILEUDF and SAS_DELETEUDF functions were dropped.
    Here is an example.
    proc sql noerrorstop;
       connect to db2 (user=abcd password=xxxx database=indbdb;);
       select * from connection to db2 (
          select cast(funcname as char(40)), 
             cast(definer as char(20)) from syscat.functions 
                where funcschema='SASLIB' );
    quit;
    
    If you are upgrading from or reinstalling only the SAS Formats Library and the binary files, skip to Step 6.
  3. Enter the following command to see whether the SAS Embedded Process is running.
    $ps -ef | grep db2sasep
    If the SAS Embedded Process is running, results similar to this are displayed.
    ps -ef | grep db2sasep
    db2v9 23265382 20840668   0   Oct 06      -  4:03 db2sasep 
    db2v9 27983990 16646196   1 08:24:09 pts/10  0:00 grep db2sasep
    
  4. Stop the DB2 SAS Embedded Process using DB2IDA command.
    Use this command to stop the SAS Embedded Process.
    $db2ida -provider sas -stop
    If the SAS Embedded Process is still running, an error occurs. Enter this command to force the SAS Embedded Process to stop.
    $db2ida -provider sas -stopforce
    For more information about the DB2IDA command, see Controlling the SAS Embedded Process for DB2.
  5. Remove the SAS directory that contain the SAS Embedded Process binary files from the DB2 instance path.
    Enter these commands to move to the db2instancepath directory and remove the SAS directory. db2instancepath is the path to the SAS Embedded Process binary files in the DB2 instance.
    $ cd db2instancepath
    $ rm -fr SAS
  6. Stop the DB2 instance.
    1. Log in to the DB2 server and enter this command to determine whether there are any users connected to the instance.
      $db2 list applications
    2. If any users are connected, enter these commands to force them off before the instance is stopped and clear any background processes.
      $db2 force applications all
      $db terminate
    3. Enter this command to stop the DB2 instance.
      $db2stop
      
  7. Remove the SAS directory from the DB2 instance path. Enter these commands to move to the db2instancepath/sqllib/function directory and remove the SAS directory. db2instancepath/sqllib/function is the path to the SAS_COMPILEUDF and SAS_DELETEUDF functions in the DB2 instance.
    $ cd db2instancepath/sqllib/function
    $ rm -fr SAS

Upgrading from or Reinstalling the SAS Embedded Process

To upgrade from or reinstall a previous version of the SAS Embedded Process, follow these steps.
Note: These steps are for upgrading from or reinstalling only the SAS Embedded Process. If you want to upgrade from or reinstall the SAS Formats Library and binary files or both the SAS Formats Library and binary files and the SAS Embedded Process, you must follow the steps in Upgrading from or Reinstalling the SAS Formats Library, Binary Files, and the SAS Embedded Process.
  1. Enter the following command to see whether the SAS Embedded Process is running.
    $ps -ef | grep db2sasep
    If the SAS Embedded Process is running, results similar to this are displayed.
    ps -ef | grep db2sasep
    db2v9 23265382 20840668   0   Oct 06      -  4:03 db2sasep 
    db2v9 27983990 16646196   1 08:24:09 pts/10  0:00 grep db2sasep
    
  2. Enter the following command to determine whether there are any users connected to the instance.
    $db2 list applications
  3. Stop the DB2 SAS Embedded Process using DB2IDA command.
    Note: If you are upgrading or reinstalling the SAS Embedded Process (tkindbsrv*.sh file), you do not need to shut down the database. The DB2IDA command enables you to upgrade or reinstall only the SAS Embedded Process components without impacting clients already connected to the database. For more information about the DB2IDA command, see Controlling the SAS Embedded Process for DB2.
    Use this command to stop the SAS Embedded Process.
    $db2ida -provider sas -stop
    If the SAS Embedded Process is still running, an error occurs. Enter this command to force the SAS Embedded Process to stop.
    $db2ida -provider sas -stopforce
  4. Remove the SAS directory that contain the SAS Embedded Process binary files from the DB2 instance path.
    Enter these commands to move to the db2instancepath directory and remove the SAS directory. db2instancepath is the path to the SAS Embedded Process binary files in the DB2 instance.
    $ cd db2instancepath
    $ rm -fr SAS

Installing the SAS Formats Library, Binary Files, and SAS Embedded Process

Move the Files to DB2

There are two self-extracting archive files (.sh files) that need to be moved to DB2. You can use PSFTP, SFTP, or FTP to transfer the self-extracting archive files to the DB2 server to be unpacked and compiled.
  • The first self-extracting archive file contains the SAS formats library and the binary files for the SAS_COMPILEUDF and SAS_DELETEUDF functions. You need these files when you want to use scoring functions to run your scoring model and when publishing SAS formats.
    This self-extracting archive file is located in the SAS-install-directory/SASFormatsLibraryForDB2/2.1/DB2on<AIX | Linux64>/ directory.
    Choose the self-extracting archive files based on the UNIX platform that your DB2 server runs on. n is a number that indicates the latest version of the file. If this is the initial installation, nhas a value of 1. Each time you reinstall or upgrade, n is incremented by 1.
    • AIX: acceldb2fmt-2.1-n_r64.sh
    • Linux(x86_64): acceldb2fmt-2.1-n_lax.sh
    The file does not have to be downloaded to a specific location, but you need to note where it is downloaded so that it can be executed as the DB2 instance owner at a later time. It is recommended that you put the acceldb2fmt file somewhere other than the DB2 home directory tree.
  • The second self-extracting archive file contains the SAS Embedded Process. You need these files if you want to use the SAS Embedded Process to run your scoring model.
    Note: The SAS Embedded Process might require a later release of DB2 than function-based scoring. Please refer to the SAS system requirements documentation.
    This self-extracting archive file is located in the SAS-install-directory/SASTKInDatabaseServer/9.31/DB2on<AIX | Linuxx64>/.
    Choose the self-extracting archive files based on the UNIX platform that your DB2 server runs on. n is a number that indicates the latest version of the file.
    • AIX: tkindbsrv-9.33-n_r64.sh
    • Linux(x86_64): tkindbsrv-9.33-n_lax.sh
    You must put the tkindbsrv file in the instance owner’s home directory.
List the directory in UNIX to verify that the files have been moved.

Unpack the SAS Formats Library and Binary Files

After the acceldb2fmt-2.1-n_lax.sh or acceldb2fmt-2.1-n_r64.sh self-extracting archive file is transferred to the DB2 machine, follow these steps to unpack the file. n is a number that indicates the latest version of the file. If this is the initial installation, n has a value of 1. Each time you reinstall or upgrade, n is incremented by 1.
  1. Log in as the user who owns the DB2 instance from a secured shell, such as SSH.
  2. Change to the directory where you put the acceldb2fmt file.
    $ cd path_to_sh_file
    path_to_sh_file is the location to which you copied the self-extracting archive file.
  3. If necessary, change permissions on the file to enable you to execute the script and write to the directory.
    $ chmod +x acceldb2fmt-2.1-n_r64.sh
    Note: AIX is the platform that is being used as an example for all the steps in this topic.
  4. If there are previous self-extracting archive files in the SAS directory, you must either rename or remove the directory. These are examples of the commands that you would use.
    $mv SAS to SAS_OLD /* rename SAS directory */
    $rm -fr SAS /* remove SAS directory */
  5. Use the following commands to unpack the appropriate self-extracting archive file.
    $ ./sh_file
    sh_file is either acceldb2fmt-2.1-n_lax.sh or acceldb2fmt-2.1-n_r64.sh depending on your platform.
    After this script is run and the files are unpacked, a SAS tree is built in the current directory. The content of the target directories should be similar to the following, depending on your operating system. Part of the directory path is shaded to emphasize the different target directories that are used.
    /path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1-n/bin/
       InstallAccelDB2Fmt.sh
    
    /path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1-n/bin/CopySASFiles.sh
    
    /path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1-n/lib/SAS_CompileUDF
    
    /path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1-n/lib/SAS_DeleteUDF
    
    /path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1-n/lib/libjazxfbrs.so
    
    /path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1 ->2.1-n
  6. Use the following command to place the files in the DB2 instance:
    $ path_to_sh_file/SAS/SASFormatsLibraryForDB2/2.1-n/bin/
       CopySASFiles.sh db2instancepath/sqllib
    
    db2instancepath/sqllib is the path to the sqllib directory of the DB2 instance that you want to use.
    After this script is run and the files are copied, the target directory should look similar to this.
    db2instancepath/sqllib/function/SAS/SAS_CompileUDF
    db2instancepath/sqllib/function/SAS/SAS_DeleteUDF
    db2instancepath/sqllib/function/SAS/libjazxfbrs.so
    
    Note: If the SAS_CompileUDF, SAS_DeleteUDF, and libjazxfbrs.so files currently exist under the target directory, you must rename the existing files before you run the CopySASFiles.sh command. Otherwise, the CopySASFiles.sh command does not work, and you get a "Text file is busy" message for each of the three files.
  7. Use the DB2SET command to tell DB2 where to find the 64-bit formats library.
    $ db2set DB2LIBPATH=db2instancepath/sqllib/function/SAS
    db2instancepath/sqllib is the path to the sqllib directory of the DB2 instance that you want to use.
    The DB2 instance owner must run this command for it to be successful. Note that this is similar to setting a UNIX system environment variable using the UNIX EXPORT or SETENV commands. DB2SET registers the environment variable within DB2 only for the specified database server.
  8. To verify that DB2LIBPATH was set appropriately, run the DB2SET command without any parameters.
    $ db2set
    The results should be similar to this one if it was set correctly.
    DB2LIBPATH=db2instancepath/sqllib/function/SAS

Unpack the SAS Embedded Process Files

After the tkindbsrv.9.33-n_lax.sh or tkindbsrv9.33-n_r64.sh self-extracting archive file has been transferred to the DB2 machine, follow these steps to unpack the file. n is a number that indicates the latest version of the file. If this is the initial installation, n has a value of 1. Each time you reinstall or upgrade, n is incremented by 1.
  1. Log in as the user who owns the DB2 instance from a secured shell, such as SSH.
  2. Change to the directory where you put the tkindbsrv file.
    $ cd path_to_sh_file
    path_to_sh_file is the location to which you copied the self-extracting archive file. This must be the instance owner home directory.
  3. If necessary, change permissions on the file to enable you to execute the script and write to the directory.
    $ chmod +x tkindbsrv-9.33-n_aix.sh
  4. If there are previous self-extracting archive files in the SAS directory, you must either rename or remove the directory. These are examples of the commands that you would use.
    $mv SAS to SAS_OLD /* rename SAS directory */
    $rm -fr SAS /* remove SAS directory */
  5. Use the following commands to unpack the appropriate self-extracting archive file.
    $ ./sh_file
    sh_file is either tkindbsrv-9.33-n_lax.sh or tkindbsrv-9.33-n_r64.sh depending on your platform.
    After this script is run and the files are unpacked, a SAS tree is built in the current directory. The target directories should be similar to the following, depending on your operating system. Part of the directory path is shaded to emphasize the different target directories that are used.
    /db2instancepath/SAS/SASTKInDatabaseServerForDB2/9.33-n/bin
    
    /db2instancepath/SAS/SASTKInDatabaseServerForDB2/9.33-n/misc
    
    /db2instancepath/SAS/SASTKInDatabaseServerForDB2/9.33-n/sasexe
    
    /db2instancepath/SAS/SASTKInDatabaseServerForDB2/9.33-n/utilities
  6. Use the DB2SET command to enable the SAS Embedded Process in DB2 and to tell the SAS Embedded Process where to find the SAS Embedded Process library files.
    $ dbset DB2_SAS_SETTINGS="ENABLE_SAS_EP:true; 
       LIBRARY_PATH:db2instancepath/SAS/SASTKInDatabaseServerForDB2/9.33-n/sasexe"
    The DB2 instance owner must run this command for it to be successful. Note that this is similar to setting a UNIX system environment variable using the UNIX EXPORT for SETENV commands. DB2SET registers the environment variable within DB2 only for the default database instance.
    For more information about all of the arguments that can be used with the DB2SET command for the SAS Embedded Process, see DB2SET Command Syntax for the SAS Embedded Process.
  7. To verify that the SAS Embedded Process is set appropriately, run the DB2SET command without any parameters.
    $ db2set
    The path should be similar to this one if it was set correctly. Note that the DB2LIBPATH that was set when you installed the SAS Formats Library and binary files is also listed.
    DB2_SAS_SETTINGS=ENABLE_SAS_EP:true 
       LIBRARY_PATH:db2instancepath/SAS/SASTKInDatabaseServerForDB2/9.33-n/sasexe
       DB2LIBPATH=db2instancepath/sqllib/function/SAS
  8. Stop the database manager instance if it is not stopped already.
    $ db2stop
    A message indicating that the stop was successful displays.
    If the database manager instance cannot be stopped because application programs are still connected to databases, use the FORCE APPLICATION command to disconnect all users, use the TERMINATE command to clear any background processes, and then use the DB2STOP command.
    $ db2 list applications
    $ db2 force applications all
    $ db2 terminate
    $ db2stop
    
  9. (AIX only) Clear the cache.
    $ su – root
    $ slibclean
    $ exit
  10. Restart the database manager instance.
    $ db2start
  11. Verify that the SAS Embedded Process started.
    $ ps -ef | grep db2sasep
    If the SAS Embedded Process was started, lines similar to the following are displayed.
    ps -ef | grep db2sasep
    db2v9 23265382 20840668   0   Oct 06      -  4:03 db2sasep 
    db2v9 27983990 16646196   1 08:24:09 pts/10  0:00 grep db2sasep
    
    In the DB2 instance, you can also verify if the SAS Embedded Process log file was created in the DB2 instance’s diagnostic directory.
    $ cd  instance-home/sqllib/db2dump
    $ ls –al sasep0.log 

DB2SET Command Syntax for the SAS Embedded Process

The syntax for the DB2SET command is shown below.
DB2SET DB2_SAS_SETTINGS="
ENABLE_SAS_EP:TRUE | FALSE;
<LIBRARY_PATH:path>
<COMM_BUFFER_SZ:size;>
<COMM_TIMEOUT:timeout;>
<RESTART_RETRIES:number-of-tries;>
<DIAGPATH:path;>
<DIAGLEVEL:level-number;>"
Arguments

ENABLE_SAS_EP:TRUE | FALSE

specifies whether the SAS Embedded Process is started with the DB2 instance.

Default FALSE

LIBRARY_PATH:path

specifies the path from which the SAS Embedded Process library is loaded

Requirement The path must be fully qualified.

COMM_BUFFER_SZ:size

specifies the size in 4K pages of the shared memory buffer that is used for communication sessions between DB2 and SAS.

Default ASLHEAPSZ dbm configuration value
Range 1–32767
Requirement size must be an integer value.

COMM_TIMEOUT:timeout

specifies a value in seconds that DB2 uses to determine whether the SAS Embedded Process is non-responsive when DB2 and SAS are exchanging control messages.

Default 600 seconds
Note If the time-out value is exceeded, DB2 forces the SAS Embedded Process to stop in order for it to be re-spawned.

RESTART_RETRIES:number-of-tries

specifies the number of times that DB2 attempts to re-spawn the SAS Embedded Process after DB2 has detected that the SAS Embedded Process has terminated abnormally.

Default 10
Range 1–100
Requirement number-of-tries must be an integer value.
Note When DB2 detects that the SAS Embedded Process has terminated abnormally, DB2 immediately attempts to re-spawn it. This argument limits the number of times that DB2 attempts to re-spawn the SAS Embedded Process. Once the retry count is exceeded, DB2 waits 15 minutes before trying to re-spawn it again.

DIAGPATH:path

specifies the path that indicates where the SAS Embedded Process diagnostic logs are written.

Default DIAGPATH dbm configuration value
Requirement The path must be fully qualified.

DIAGLEVEL:level-number

specifies the minimum severity level of messages that are captured in the SAS Embedded Process diagnostic logs. The levels are defined as follows.

1 SEVERE
2 ERROR
3 WARNING
4 INFORMATIONAL
Default DIAGLEVEL dbm configuration value
Range 1–4

Controlling the SAS Embedded Process for DB2

The SAS Embedded Process starts when a query is submitted. The SAS Embedded Process continues to run until it is manually stopped or the database is shut down.
The DB2IDA command is a utility that is installed with the DB2 server to control the SAS Embedded Process. The DB2IDA command enables you to manually stop and restart the SAS Embedded Process without shutting down the database. You might use the DB2IDA command to upgrade or reinstall the SAS Embedded Process library or correct an erroneous library path.
Note: DB2IDA requires IBM Fixpack 6 or later.
The DB2IDA command has the following parameters:
-provider sas
specifies the provider that is targeted by the command. The only provider that is supported is "sas".
-start
starts the SAS Embedded Process on the DB2 instance if the SAS Embedded Process is not currently running.
If the SAS Embedded Process is running, this command has no effect.
Note: Once the SAS Embedded Process is started, the normal re-spawn logic in DB2 applies if the SAS Embedded Process is abnormally terminated.
–stop
stops the SAS Embedded Process if it is safe to do so.
If the SAS Embedded Process is stopped, this command has no effect.
If any queries are currently running on the SAS Embedded Process, the db2ida -stop command fails and indicates that the SAS Embedded Process is in use and could not be stopped.
Note: DB2 does not attempt to re-spawn the SAS Embedded Process once it has been stopped with the db2ida -stop command.
-stopforce
forces the SAS Embedded Process to shut down regardless of whether there are any queries currently running on it.
If the SAS Embedded Process is stopped, this command has no effect.
If any queries are currently running on the SAS Embedded Process, those queries receive errors.
Note: DB2 does not attempt to re-spawn the SAS Embedded Process once it has been stopped with the db2ida -stopforce command.
Here are some examples of the DB2IDA command:
db2ida --provider sas --stopforce

db2ida --provider sas -start

Running the %INDB2_PUBLISH_COMPILEUDF Macro

Overview of the %INDB2_PUBLISH_COMPILEUDF Macro

The %INDB2_PUBLISH_COMPILEUDF macro publishes the following components to the SASLIB schema in a DB2 database:
  • SAS_COMPILEUDF function
    The SAS_COMPILEUDF function facilitates the %INDB2_PUBLISH_FORMATS format publishing macro and the %INDB2_PUBLISH_MODEL scoring publishing macro when you use scoring functions to run the scoring model. The SAS_COMPILEUDF function performs the following tasks:
    • compiles the format and scoring model source files into object files. This compilation occurs through the SQL interface using an appropriate compiler for the system.
    • links with the SAS formats library that is needed for format and scoring model publishing.
    • copies the object files to the db2instancepath/sqllib/function/SAS directory. You specify the value of db2instancepath in the %INDB2_PUBLISH_COMPILEUDF macro syntax.
  • SASUDF_DB2PATH and SASUDF_COMPILER_PATH global variables
    The SASUDF_DB2PATH and the SASUDF_COMPILER_PATH global variables are used when you publish the format and scoring model functions.
You have to run the %INDB2_PUBLISH_COMPILEUDF macro only one time in a given database.
The SAS_COMPILEUDF function must be published before you run the %INDB2_PUBLISH_DELETEUDF macro, the %INDB2_PUBLISH_FORMATS macro, and the %INDB2_PUBLISH_MODEL macro. Otherwise, these macros fail.
Note: To publish the SAS_COMPILEUDF function, you must have the appropriate DB2 user permissions to create and execute this function in the SASLIB schema and in the specified database. For more information, see DB2 Permissions.

%INDB2_PUBLISH_COMPILEUDF Macro Run Process

To run the %INDB2_PUBLISH_COMPILEUDF macro, follow these steps:
  1. Create a SASLIB schema in the database where the SAS_COMPILEUDF function is to be published.
    The SASLIB schema is used when publishing the %INDB2_PUBLISH_COMPILEUDF macro for DB2 in-database processing.
    You specify that database in the DATABASE argument of the %INDB2_PUBLISH_COMPILEUDF macro. For more information, see %INDB2_PUBLISH_COMPILEUDF Macro Syntax.
    The SASLIB schema contains the SAS_COMPILEUDF and SAS_DELETEUDF functions and the SASUDF_DB2PATH and SASUDF_COMPILER_PATH global variables.
  2. Start SAS 9.3 and submit the following commands in the Enhanced Editor or Program Editor:
    %indb2pc;
    %let indconn = server=yourserver user=youruserid password=yourpwd
       database=yourdb schema=saslib;
    
    For more information, see %INDB2PC Macro and INDCONN Macro Variable.
  3. Run the %INDB2_PUBLISH_COMPILEUDF macro. For more information, see %INDB2_PUBLISH_COMPILEUDF Macro Syntax.
You can verify that the SAS_COMPILEUDF function and global variables have been published successfully. For more information, see Validating the Publishing of SAS_COMPILEUDF and SAS_DELETEUDF Functions and Global Variables.
After the SAS_COMPILEUDF function is published, run the %INDB2_PUBLISH_DELETEUDF publishing macro to create the SAS_DELETEUDF function. For more information, see Running the %INDB2_PUBLISH_DELETEUDF Macro.

%INDB2PC Macro

The %INDB2PC macro is an autocall library that initializes the %INDB2_PUBLISH_COMPILEUDF macro.

INDCONN Macro Variable

The INDCONN macro variable provides the credentials to make a connection to DB2. You must specify the server, user, password, and database information to access the machine on which you have installed the DB2 database. You must assign the INDCONN macro variable before the %INDB2_PUBLISH_COMPILEUDF macro is invoked.
The value of the INDCONN macro variable for the %INDB2_PUBLISH_COMPILEUDF macro has this format.
SERVER=server USER=userid PASSWORD=password
DATABASE=database <SCHEMA=SASLIB>

SERVER=server

specifies the DB2 server name or the IP address of the server host. If the server name contains spaces or nonalphanumeric characters, enclose the server name in quotation marks.

Requirement The name must be consistent with how the host name was cached when PSFTP server was run from the command window. If the full server name was cached, you must use the full server name in the SERVER argument. If the short server name was cached, you must use the short server name. For example, if the long name, disk3295.unx.comp.com, is used when PSFTP was run, then server=disk3295.unx.comp.com must be specified. If the short name, disk3295, was used, then server=disk3295 must be specified. For more information, see DB2 Installation and Configuration Steps.

USER=userid

specifies the DB2 user name (also called the user ID) that is used to connect to the database. If the user name contains spaces or nonalphanumeric characters, enclose the user name in quotation marks.

PASSWORD=password

specifies the password that is associated with your DB2 user ID. If the password contains spaces or nonalphabetic characters, enclose the password in quotation marks.

Tip You can use only PASSWORD=, PASS=, or PW= for the password argument. PWD= is not supported and causes an error.

DATABASE=database

specifies the DB2 database that contains the tables and views that you want to access. If the database name contains spaces or nonalphanumeric characters, enclose the database name in quotation marks.

Requirement The SAS_COMPILEUDF function is created as a Unicode function. If the database is not a Unicode database, then the alternate collating sequence must be configured to use identity_16bit.

SCHEMA=SASLIB

specifies SASLIB as the schema name.

Default SASLIB
Restriction The SAS_COMPILEUDF function and the two global variables (SASUDF_DB2PATH and SASUDF_COMPILER_PATH) are published to the SASLIB schema in the specified database. If a value other than SASLIB is used, it is ignored.
Requirement The SASLIB schema must be created before publishing the SAS_COMPILEUDF and SAS_DELETEUDF functions.

%INDB2_PUBLISH_COMPILEUDF Macro Syntax

%INDB2_PUBLISH_COMPILEUDF
(DB2PATH=db2instancepath/sqllib
, COMPILER_PATH=compiler-path-directory
<, DATABASE=database-name>
<, ACTION=CREATE | REPLACE | DROP>
<, OBJNAME=object-file-name>
<, OUTDIR=diagnostic-output-directory>
);
Arguments

DB2PATH=db2instancepath/sqllib

specifies the parent directory that contains the function/SAS subdirectory, where all the object files are stored and defines the SASUDF_DB2PATH global variable that is used when publishing the format and scoring model functions.

Interaction db2instancepath should be the same path as the path that was specified during the installation of the SAS_COMPILEUDF binary file. For more information, see Step 3 in Unpack the SAS Formats Library and Binary Files.
Tip The SASUDF_DB2PATH global variable is defined in the SASLIB schema under the specified database name.

COMPILER_PATH=compiler-path-directory

specifies the path to the location of the compiler that compiles the source files and defines the SASUDF_COMPILER_PATH global variable that is used when publishing the format and scoring model functions.

Tip The SASUDF_COMPILER_PATH global variable is defined in the SASLIB schema under the specified database name. The XLC compiler should be used for AIX, and the GGG compiler should be used for Linux.

DATABASE=database-name

specifies the name of a DB2 database to which the SAS_COMPILEUDF function is published.

Interaction: The database that you specify in the DATABASE= argument takes precedence over the database that you specify in the INDCONN macro variable. For more information, see %INDB2_PUBLISH_COMPILEUDF Macro Run Process.

ACTION=CREATE | REPLACE | DROP

specifies that the macro performs one of the following actions:

CREATE

creates a new SAS_COMPILEUDF function.

REPLACE

overwrites the current SAS_COMPILEUDF function, if a SAS_COMPILEUDF function by the same name is already registered, or creates a new SAS_COMPILEUDF function if one is not registered.

DROP

causes the SAS_COMPILEUDF function to be dropped from the DB2 database.

Default CREATE
Tip If the SAS_COMPILEUDF function was published previously and you now specify ACTION=CREATE, you receive warning messages from DB2. If the SAS_COMPILEUDF function was published previously and you specify ACTION=REPLACE, no warnings are issued.

OBJNAME=object-file-name

specifies the object filename that the publishing macro uses to register the SAS_COMPILEUDF function. The object filename is a file system reference to a specific object file, and the value entered for OBJNAME must match the name as it exists in the file system. For example, SAS_CompileUDF is mixed case.

Default SAS_CompileUDF
Interaction If the SAS_COMPILEUDF function is updated, you might want to rename the object file to avoid stopping and restarting the database. If so, the SAS_COMPILEUDF function needs to be reregistered with the new object filename.

OUTDIR=output-directory

specifies a directory that contains diagnostic files.

Tip Files that are produced include an event log that contains detailed information about the success or failure of the publishing process.

Running the %INDB2_PUBLISH_DELETEUDF Macro

Overview of the %INDB2_PUBLISH_DELETEUDF Macro

The %INDB2_PUBLISH_DELETEUDF macro publishes the SAS_DELETEUDF function in the SASLIB schema of a DB2 database. The SAS_DELETEUDF function facilitates the %INDB2_PUBLISH_FORMATS format publishing macro and the %INDB2_PUBLISH_MODEL scoring publishing macro. The SAS_DELETEUDF function removes existing object files when the format or scoring publishing macro registers new ones by the same name.
You have to run the %INDB2_PUBLISH_DELETEUDF macro only one time in a given database.
The SAS_COMPILEUDF function must be published before you run the %INDB2_PUBLISH_DELETEUDF macro, the %INDB2_PUBLISH_FORMATS macro, and the %INDB2_PUBLISH_MODEL macro. Otherwise, these macros fail.
Note: To publish the SAS_DELETEUDF function, you must have the appropriate DB2 user permissions to create and execute this function in the SASLIB schema and specified database. For more information, see DB2 Permissions.

%INDB2_PUBLISH_DELETEUDF Macro Run Process

To run the %INDB2_PUBLISH_DELETEUDF macro, follow these steps:
  1. Ensure that you have created a SASLIB schema in the database where the SAS_DELETEUDF function is to be published.
    Use the SASLIB schema when publishing the %INDB2_PUBLISH_DELETEUDF macro for DB2 in-database processing.
    The SASLIB schema should have been created before you ran the %INDB2_PUBLISH_COMPILEUDF macro to create the SAS_COMPILEUDF function. The SASLIB schema contains the SAS_COMPILEUDF and SAS_DELETEUDF functions and the SASUDF_DB2PATH and SASUDF_COMPILER_PATH global variables.
    The SAS_COMPILEUDF function must be published before you run the %INDB2_PUBLISH_DELETEUDF macro. The SAS_COMPILEUDF and SAS_DELETEUDF functions must be published to the SASLIB schema in the same database. For more information about creating the SASLIB schema, see %INDB2_PUBLISH_COMPILEUDF Macro Run Process.
  2. Start SAS 9.3 and submit the following commands in the Enhanced Editor or Program Editor.
    %indb2pd;
    %let indconn = server=yourserver user=youruserid password=yourpwd
       database=yourdb schema=saslib;
    
    For more information, see %INDB2PD Macro and INDCONN Macro Variable.
  3. Run the %INDB2_PUBLISH_DELETEUDF macro. For more information, see %INDB2_PUBLISH_DELETEUDF Macro Syntax.
You can verify that the function has been published successfully. For more information, see Validating the Publishing of SAS_COMPILEUDF and SAS_DELETEUDF Functions and Global Variables.
After the SAS_DELETEUDF function is published, the %INDB2_PUBLISH_FORMATS and the %INDB2_PUBLISH_MODEL macros can be run to publish the format and scoring model functions.

%INDB2PD Macro

The %INDB2PD macro is an autocall library that initializes the %INDB2_PUBLISH_DELETEUDF macro.

INDCONN Macro Variable

The INDCONN macro variable provides the credentials to make a connection to DB2. You must specify the server, user, password, and database information to access the machine on which you have installed the DB2 database. You must assign the INDCONN macro variable before the %INDB2_PUBLISH_DELETEUDF macro is invoked.
The value of the INDCONN macro variable for the %INDB2_PUBLISH_DELETEUDF macro has this format.
SERVER=server USER=userid PASSWORD=password
DATABASE=database <SCHEMA=SASLIB>

SERVER=server

specifies the DB2 server name or the IP address of the server host. If the server name contains spaces or nonalphanumeric characters, enclose the server name in quotation marks.

Requirement The name must be consistent with how the host name was cached when PSFTP server was run from the command window. If the full server name was cached, use the full server name in the SERVER argument. If the short server name was cached, use the short server name. For example, if the long name, disk3295.unx.comp.com, is used when PSFTP was run, then server=disk3295.unx.comp.com must be specified. If the short name, disk3295, was used, then server=disk3295 must be specified. For more information, see DB2 Installation and Configuration Steps.

USER=userid

specifies the DB2 user name (also called the user ID) that is used to connect to the database. If the user name contains spaces or nonalphanumeric characters, enclose the user name in quotation marks.

PASSWORD=password

specifies the password that is associated with your DB2 user ID. If the password contains spaces or nonalphabetic characters, enclose the password in quotation marks.

Tip You can use only PASSWORD=, PASS=, or PW= for the password argument. PWD= is not supported and causes errors.

DATABASE=database

specifies the DB2 database that contains the tables and views that you want to access. If the database name contains spaces or nonalphanumeric characters, enclose the database name in quotation marks.

SCHEMA=SASLIB

specifies SASLIB as the schema name.

Default SASLIB
Restriction The SAS_DELETEUDF function is published to the SASLIB schema in the specified database. If a value other than SASLIB is used, it is ignored.
Requirement Create the SASLIB schema before publishing the SAS_COMPILEUDF and SAS_DELETEUDF functions.

%INDB2_PUBLISH_DELETEUDF Macro Syntax

%INDB2_PUBLISH_DELETEUDF
(<DATABASE=database-name>
<, ACTION=CREATE | REPLACE | DROP>
<, OUTDIR=diagnostic-output-directory>
);
Arguments

DATABASE=database-name

specifies the name of a DB2 database to which the SAS_DELETEUDF function is published.

Interaction The database that you specify in the DATABASE argument takes precedence over the database that you specify in the INDCONN macro variable. For more information, see Running the %INDB2_PUBLISH_DELETEUDF Macro.

ACTION=CREATE | REPLACE | DROP

specifies that the macro performs one of the following actions:

CREATE

creates a new SAS_DELETEUDF function.

REPLACE

overwrites the current SAS_DELETEUDF function, if a SAS_DELETEUDF function by the same name is already registered, or creates a new SAS_DELETEUDF function if one is not registered.

DROP

causes the SAS_DELETEUDF function to be dropped from the DB2 database.

Default CREATE
Tip If the SAS_DELTEUDF function was published previously and you specify ACTION=CREATE, you receive warning messages from DB2. If the SAS_DELETEUDF function was published previously and you specify ACTION=REPLACE, no warnings are issued.

OUTDIR=diagnostic-output-directory

specifies a directory that contains diagnostic files.

Tip Files that are produced include an event log that contains detailed information about the success or failure of the publishing process.

Validating the Publishing of SAS_COMPILEUDF and SAS_DELETEUDF Functions and Global Variables

To validate that the SAS_COMPILEUDF and SAS_DELETEUDF functions and global variables are created properly, follow these steps.
  1. Connect to your DB2 database using Command Line Processor (CLP).
  2. Enter the following command to verify that the SASUDF_COMPILER_PATH global variable was published.
    values(saslib.sasudf_compiler_path)
    You should receive a result similar to one of the following.
    /usr/vac/bin      /* on AIX */
    /usr/bin        /* on Linux */
    
  3. Enter the following command to verify that the SASUDF_DB2PATH global variable was published.
    values(saslib.sasudf_db2path)
    You should receive a result similar to the following.
    /users/db2v9/sqllib
    In this example, /users/db2v9 is the value of db2instancepath that was specified during installation and /users/db2v9/sqllib is also where the SAS_COMPILEUDF function was published.
  4. Enter the following command to verify that theSAS_COMPILEUDF and SAS_DELETEUDF functions were published.
    select funcname, implementation from syscat.functions where
       funcschema='SASLIB'
    
    You should receive a result similar to the following.
    FUNCNAME                         IMPLEMENTATION
    -------------------------------------------------------------
    SAS_DELETEUDF
    /users/db2v9/sqllib/function/SAS/SAS_DeleteUDF!SAS_DeleteUDF
    SAS_COMPILEUDF
    /users/db2v9/sqllib/function/SAS/SAS_CompileUDF!SAS_CompileUDF
    

DB2 Permissions

There are two sets of permissions involved with the in-database software.
  • The first set of permissions is needed by the person who publishes the SAS_COMPILEUDF and SAS_DELETEUDF functions and creates the SASUDF_COMPILER_PATH and SASUDF_DB2PATH global variables.
    These permissions must be granted before the %INDB2_PUBLISH_COMPILEUDF and %INDB2_PUBLISH_DELETEUDF macros are run. Without these permissions, running these macros fails.
    The following table summarizes the permissions that are needed by the person who publishes the functions and creates the global variables.
    Permission Needed
    Authority Required to Grant Permission
    Examples
    CREATEIN permission for the SASLIB schema in which the SAS_COMPILEUDF and SAS_DELETEUDF functions are published and the SASUDF_COMPILER_PATH and SASUDF_DB2PATH global variables are defined
    System Administrator or Database Administrator
    Note: If you have SYSADM or DBADM authority or are the DB2 instance owner, then you have these permissions. Otherwise, contact your database administrator to obtain these permissions.
    GRANT CREATEIN ON SCHEMA SASLIB 
    TO compiledeletepublisheruserid
    CREATE_EXTERNAL_ROUTINE permission to the database in which the SAS_COMPILEUDF and SAS_DELETEUDF functions are published
    GRANT CREATE_EXTERNAL_ROUTINE ON 
    DATABASE TO 
    compiledeletepublisheruserid
  • The second set of permissions is needed by the person who publishes the format or scoring model functions. The person who publishes the format or scoring model functions is not necessarily the same person who publishes the SAS_COMPILEUDF and SAS_DELETEUDF functions and creates the SASUDF_COMPILER_PATH and SASUDF_DB2PATH global variables. These permissions are most likely needed by the format publishing or scoring model developer. Without these permissions, the publishing of the format or scoring model functions fails.
    Note: Permissions must be granted for every format or scoring model publisher and for each database that the format or scoring model publishing uses. Therefore, you might need to grant these permissions multiple times.
    Note: If you are using the SAS Embedded Process to run your scoring functions, only the CREATE TABLE permission is needed.
    After the DB2 permissions have been set appropriately, the format or scoring publishing macro should be called to register the formats or scoring model functions.
    The following table summarizes the permissions that are needed by the person who publishes the format or scoring model functions.
    Permission Needed
    Authority Required to Grant Permission
    Examples
    EXECUTE permission for functions that have been published.
    This enables the person who publishes the formats or scoring model functions to execute the SAS_COMPILEUDF and SAS_DELETEUDF functions.
    System Administrator or Database Administrator
    Note: If you have SYSADM or DBADM authority, then you have these permissions. Otherwise, contact your database administrator to obtain these permissions.
    GRANT EXECUTE ON FUNCTION 
    SASLIB.* TO 
    scoringorfmtpublisherid
    CREATE_EXTERNAL_ROUTINE permission to the database to create format or scoring model functions
    GRANT CREATE_EXTERNAL_ROUTINE ON 
    DATABASE TO 
    scoringorfmtpublisherid
    CREATE_NOT_FENCED_ROUTINE permission to create format or scoring model functions that are not fenced
    GRANT CREATE_NOT_FENCED_ROUTINE 
    ON DATABASE TO 
    scoringorfmtpublisherid
    CREATEIN permission for the schema in which the format or scoring model functions are published if the default schema (SASLIB) is not used
    GRANT CREATEIN ON SCHEMA 
    scoringschema TO 
    scoringorfmtpublisherid
    CREATE TABLE permission to create the model table used in with scoring and the SAS Embedded Process
    GRANT CREATE TABLE TO 
    scoringpublisherSEPid
    READ permission to read the SASUDF_COMPILER_PATH and SASUDF_DB2PATH global variables
    Note: The person who ran the %INDB2_PUBLISH_COMPILEUDF macro has these READ permissions and does not need to grant them to himself or herself again.
    Person who ran the %INDB2_PUBLISH_COMPILEUDF macro
    Note: For security reasons, only the user who created these variables has the permission to grant READ permission to other users. This is true even for the user with administrator permissions such as the DB2 instance owner.
    GRANT READ ON VARIABLE 
    SASLIB.SASUDF_DB2PATH TO 
    scoringorfmtpublisherid
    
    GRANT READ ON VARIABLE 
    SASLIB.SASUDF_COMPILER_PATH
    TO scoringorfmtpublisherid
Note: If you plan to use SAS Model Manager with the SAS Scoring Accelerator for in-database scoring, additional permissions are required. For more information, see Configurations for SAS Model Manager.

Documentation for Publishing SAS Formats or Scoring Models in DB2

For information about how to publish SAS formats or scoring models, see the SAS In-Database Products: User's Guide, located at http://support.sas.com/documentation/onlinedoc/indbtech/index.html.