DBCONTERM= LIBNAME Statement Option

Specifies a user-defined termination command to execute before every disconnect from the DBMS that is within the scope of the LIBNAME statement or libref.

Valid in: SAS/ACCESS LIBNAME statement
CONNECT statement
Category: Data Set Control
Aliases: DBTERMCMD [Vertica]
TERMCMD [Vertica]
Default: none
Data source: Amazon Redshift, Aster, DB2 under UNIX and PC Hosts, DB2 under z/OS, Greenplum, Hadoop, HAWQ, Impala, Informix, JDBC, Microsoft SQL Server, MySQL, Netezza, ODBC, OLE DB, Oracle, PostgreSQL, SAP ASE, SAP HANA, SAP IQ, Snowflake, Spark, Teradata, Vertica, Yellowbrick
Notes: Support for Spark was added in SAS 9.4M7.
Support for Yellowbrick was added in SAS 9.4M7.
See: DBCONINIT= LIBNAME option

Syntax

DBCONTERM=<'>DBMS-user-command<'>

Syntax Description

DBMS-user-command

any valid command that the SAS/ACCESS engine can execute and that does not return a result set or output parameters.

Details

The termination command that you select can be a stored procedure or any DBMS SQL statement that might provide additional control over the interaction between the SAS/ACCESS engine and the DBMS. The command executes immediately before SAS terminates each connection to the DBMS. If the command fails, SAS provides a warning message, but SAS still unassigns the library and disconnects from the DBMS. You must specify the command as a single quoted string.

Note: The termination command might execute more than once because one LIBNAME statement might have multiple connections (for example, one for reading and one for updating).

Examples

Example 1: Drop a Table Before Disconnecting

In this example, the DBMS drops the Q1_SALES table before SAS disconnects from the DBMS.

libname mydblib db2 user=myusr1 using=mypwd1
        datasrc=invoice dbconterm='drop table q1_sales';

Example 2: Execute a Stored Procedure at Each DBMS Connection

In this example, the stored procedure, SALESTAB_STORED_PROC, is executed each time SAS connects to the DBMS, and the BONUSES table is dropped when SAS terminates each connection.

libname mydblib db2 user=myusr1
        using=mypwd1 datasrc=sales
        dbconinit='exec salestab_stored_proc'
        dbconterm='drop table bonuses';
Last updated: February 3, 2026