Sunday, July 24, 2011

Checkpoint and Restart Modes

SAS 9.3 lets you divide a program into segments, each of which consists of one or more steps, so that you can automatically restart the program where it left off. This is useful for large-scale programs that may occasionally run into trouble because of their extensive use of system resources.

To simplify somewhat, you divide a program into segments by writing statement labels before the first DATA or PROC statement and selected DATA and PROC statements that follow, plus one more at the end of the program. These labeled statements are the points where the program will resume when you restart it after it fails. The reason the program is able to restart is that SAS saves information about the state of the session in a checkpoint library, whenever the program gets to the next checkpoint without error.

This is all controlled by system options: LABELCHKPT to run a program using checkpoints; LABELCHKPTLIB= to select a checkpoint library other than the WORK library; and if a program fails, LABELRESTART to restart a program at the last checkpoint before the point of failure. SAS also recommends the NOWORKINIT, NOWORKTERM, ERRORCHECK, and ERRORABEND system options to preserve the WORK library and collect valid checkpoint data. If you are running in an environment where it isn’t practical to preserve the WORK library, rewrite the program to use another library instead.

I couldn’t count the number of times I’ve restarted a program manually by erasing the beginning steps in a program, then adding in the appropriate OPTIONS and TITLE statements, in order to rerun the end of it. That approach fails so often, though, that I often prefer to restart a program from the beginning, despite the use of computer resources. The checkpoint and restart modes take the guesswork out of restarting a program, so that you can restart somewhere in the middle without having to create a modified version the program.

If you don’t know where a program might fail, you might prefer to use step checkpoints rather than labeled checkpoints. In this mode, SAS automatically creates a checkpoint for every step. Use the system options STEPCHKPT, STEPCHKPTLIB, and STEPRESTART.

If there is a step that has to run every time, even in restart mode, mark the step with this statement, before the DATA or PROC statement:


With this statement, the step runs every time the program runs, regardless of restart mode.

No comments:

Post a Comment