Exiting or Interrupting Your SAS Session in UNIX Environments

Methods for Exiting SAS

Use one of the following methods to exit a SAS session:
  • Select Filethen selectExit if you are using SAS in the windowing environment.
  • Use endsas;.
  • Enter BYE in the ToolBox if you are using SAS in the windowing environment.
  • Use CTRL+D if this control key sequence is your EOF command and if you are using SAS in interactive line mode.

Methods for Interrupting or Terminating SAS

Interrupting or Terminating SAS

In addition to the methods for exiting SAS, SAS provides methods for interrupting or terminating a SAS session. SAS does not recommend that you use these methods until you have tried to exit SAS by one of the methods listed in Methods for Exiting SAS.
You can interrupt or terminate SAS in the following ways:
  • Press the interrupt or quit control key. Interrupt will display a dialog box, while quit will force a shutdown. Using the quit control key is not recommended.
  • Use the SAS: Session Management window.
  • Enter the UNIX kill command. Use this command when all other methods of exiting SAS have failed. By default, the kill command is kill –15 (SIGTERM).
    Using the UNIX kill —9 command on a SAS process that is running might corrupt data sets that are open for Write or Update access.

Interrupting a SAS Process

The method that you use to interrupt a SAS process depends on how you invoke SAS.
  • If you are running SAS in interactive line mode or in batch mode in the foreground, then you can use either of the following methods to interrupt SAS:
    • Press the control key sequence that is set to interrupt in the shell that invoked SAS. In most cases, this control key sequence is CTRL+C. See the man page for the stty command to determine the appropriate control key sequence for your environment.
    • Use the -SIGINT option in the kill command. For more information, see Using the UNIX kill Command.
  • If you are running the SAS windowing environment in the foreground, then click Interrupt in the SAS: Session Management window.
    SAS: Session Management window
    Note: You can access the SAS Session Manager by invoking SAS with the -DMS or -DMSEXP option. Select SAS: Session Management from the menu.
  • If you are running SAS in batch mode, you must use control keys to interrupt the SAS process. A SAS: Session Management window is not available.
The interrupt signal sends a request to the supervisor to handle an interrupt. The interrupt signal is not handled until a safe point in the code is reached. A safe point is one that allows the interrupt handler to be run safely. The supervisor responds as soon as possible with a prompt or window that requests what type of interrupt action you want to take. During this time, normal processing of a DATA step or PROC step is suspended.
For example, when you interrupt a DATA step or PROC step, a Tasking Manager window, similar to the following, appears:
Tasking Manager window
The following table explains each of the options in the window:
Options in the Tasking Manager Window
Option
Description
What This Option Does
1
Cancel Submitted Statements
Selecting this option terminates the current DATA step or PROC step. Outstanding source code that is waiting to execute is flushed from the system. In interactive line mode, you return to the command prompt.
2
Halt DATA step/PROC: DATASTEP
Selecting this option sends an interrupt signal to the DATA step or PROC step. The default behavior is for the DATA step or PROC step to terminate, and to execute the next statement.
A procedure might specify its own handler to process the interrupt. In this case, the procedure might request more input from you. For example, SAS webAF has a different interrupt menu than PROC SQL.
Note: If you are using a relational database, the interrupt signal might be handled differently, depending on which relational database you are using.
C
Cancel the dialog
Selecting this option cancels the interrupt, and you return to normal processing.
T
Terminate the SAS System
Selecting this option causes the DATA step or PROC step to be terminated. Outstanding source code that is waiting to execute is flushed from the system. SAS exits as cleanly as possible.

Terminating a SAS Process

If you are running the SAS windowing environment in the foreground, click Terminate in the SAS: Session Management window. If you are running a SAS process in interactive line mode in the background, use control keys to terminate the SAS process, or use the kill command.
If you click Terminate in the SAS: Session Management window, a dialog box appears, confirming that you want to end the session. If you click OK, then the SAS session and any queries that are currently running are terminated. If you click Cancel, you are returned to the SAS session.

Using Control Keys

Control keys enable you to interrupt or terminate your session by pressing the interrupt or quit key sequence. However, control keys can be used only when your SAS program is running in interactive line mode or in batch mode in the foreground. You cannot use control keys to stop a background job.
Note: You cannot use control keys to stop a batch job that has been submitted with the batch, at, nohup, or cron command.
Because control keys vary from system to system, issue the UNIX stty command to determine which key sends which signal. The stty command varies considerably among UNIX operating environments, so check the UNIX man page for stty before using the command. Usually, one of these forms of the command will print all of the current terminal settings:
stty
stty -a
stty everything
The output should contain lines similar to these:
intr = ^C; quit = ^\; erase = ^H; 
kill = ^U; eof = ^D; eol = ^@
The caret (^) represents the CTRL key. In this example, CTRL+C is the interrupt key and CTRL+\ is the quit key. Quit is a more forceful termination and might result in data corruption. If you use –SIGTERM, SAS attempts to shut down the system correctly.

Using the SAS Session Manager

If you invoke SAS in the windowing environment, you can use the SAS session manager to interrupt or terminate your SAS session. The SAS session manager is automatically minimized when you start SAS. To interrupt or terminate your SAS session, open the SAS: Session Management window and click Interrupt or Terminate:
SAS: Session Management window
If asynchronous SAS/CONNECT tasks are running when you terminate a SAS session, these tasks are terminated and no warning message is displayed. Generally, it is better to exit from the file menu or tool box.
Note: Clicking Interrupt is equivalent to specifying the -SIGINT option on the kill command. Clicking Terminate is equivalent to specifying the -SIGTERM option on the kill command.
For more information about the SAS Session Manager, see The SAS Session Manager (motifxsassm) in UNIX.

Using the UNIX kill Command

Note: Use the kill command only after you have tried all other methods to exit your SAS session.
The kill command sends an interrupt or terminate signal to SAS, depending on which signal you specify. You can use the kill command to interrupt or terminate a SAS session running in any mode. The kill command cannot be issued from within a SAS session. You must issue it from another terminal or from another window (if your terminal permits it).
The format of the kill command is:
kill <-signal-name> pid
To send the interrupt signal, specify -SIGINT. To send the terminate signal, specify -SIGTERM. Use the ps command and its options to determine the process identification number (pid) of the SAS session that you want to interrupt or terminate.
The results of using the ps command differ in different operating environments. See the UNIX man page for your operating environment for specific information about the ps command and its options. Adding options helps to determine which process you want to kill if you have more than one SAS process running. Also, servers (metadata, OLAP, and so on) leave a process identification number in their start-up directories. You can use this number with the kill command.
The following table lists some of the important kill signals.
Description of Important kill Signals
Signal
Option
Description
0
SIGNULL
Checks access to process identifier.
1
SIGHUP
Causes SAS to terminate.
2
SIGINT
Causes SAS to interrupt the session. SIGINT is very similar to SIGQUIT.
3
SIGQUIT
Causes a more forceful shutdown than SIGTERM. It does not cause a core dump.
9
SIGKILL
Brings down SAS. Use this option only after all attempts to exit SAS have failed. Using SIGKILL can cause data corruption.
15
SIGTERM
Causes SAS to terminate.
For more information, see the UNIX man pages for the ps and kill commands.

Messages in the Console Log (STDOUT)

If SAS encounters an error or warning condition when the SAS log is not available, then any messages that SAS issues are written to the console log. Normally, the SAS log is unavailable only early in SAS initialization and late in SAS termination.
If you are using the -STDIO option, the log is displayed in stderr, and the listing is displayed in stdout.