Previous Page | Next Page

SAS Component Language Dictionary

CONTROL



Controls the execution of labeled program sections and the formatting of submit blocks
Category: Control Flow
Comparisons: SAS Statement with limitations in SCL

Syntax
Details
Examples
Example 1: Using the ASIS Option
Example 2: Controlling a Program Interrupt
See Also

Syntax

CONTROL options;

options

specify the type of control for program statements. The available options are described below. You can use one or more options.

Type: Character

ALLCMDS|NOALLCMDS

NOALLCMDS is in effect by default. Global or procedure-specific commands execute immediately without executing the SCL program. The program cannot intercept any procedure-specific commands that are issued in the application. Use CONTROL ALLCMDS to enable SCL to intercept procedure-specific or custom commands that are issued in the application. You can use the NEXTCMD routine to ignore invalid commands. Use CONTROL NOALLCMDS to restore the default behavior.

ALLCMDS provides the same functionality as the ALWAYS option and enables a program to intercept custom commands. In addition, ALLCMDS allows an SCL program to intercept procedure-specific commands.

In PROGRAM entries, ALLCMDS combines the effects of ENTER and ERROR and forces statements in the MAIN section to execute even if a user issues commands that are not recognized by the procedure.

In FSEDIT applications, ALLCMDS and ALWAYS have the same functionality, and both enable an SCL program to intercept any procedure-specific or custom commands.

When ALLCMDS is specified, statements execute in the MAIN section before a command that is issued with the EXECCMD routine. This behavior could introduce an infinite loop. Either execute the EXECCMD routine conditionally or specify the command using EXECCMDI with the NOEXEC parameter.

FSVIEW applications ignore these options.

ALWAYS|NOALWAYS

NOALWAYS is in effect by default. The MAIN section executes only when a user modifies a window variable with a valid value and then presses either ENTER or a function key. Use CONTROL ALWAYS to force statements in the MAIN section to execute even if a user issues commands that are not recognized by the procedure. ALWAYS combines the effects of ENTER and ERROR.

ALWAYS can be used if your application supports custom commands. When ALWAYS is specified, FSEDIT applications execute statements in the MAIN section before handling a command that is issued with the EXECCMD routine. This behavior could introduce an infinite loop. Either execute the EXECCMD routine conditionally or specify the command using EXECCMDI with the NOEXEC parameter.

FSVIEW applications ignore this option.

ASIS|NOASIS

NOASIS is in effect by default. SCL formats submit-block code and eliminates unnecessary spaces and line breaks. Use CONTROL ASIS so that submit blocks are submitted without formatting. You must use this option when the position of elements in the SAS code is important (for example, if you are submitting a DATALINES statement with a DATA step). ASIS is more efficient than NOASIS because it reduces the time spent on formatting.

BREAK label|NOBREAK

NOBREAK is in effect by default. If a program interrupt occurs while the SCL statements are executing, a window opens and asks the user whether program execution should resume (that is, ignore the interrupt) or the program should quit. If a user chooses to quit execution, no more statements are executed for the current program, and control returns to the calling program. Use CONTROL BREAK so that you can specify a labeled section to which control passes if an interrupt or break condition occurs while the SCL statements are executing. Label is the program label of the section to execute after the current statement finishes execution. This labeled section can include SCL statements that report status and handle the interrupt. Use the _STATUS_ system variable to control execution such as H to halt and R to resume.

A program can contain any number of CONTROL BREAK statements. For example, there can be one in each of the INIT, MAIN, and TERM sections or in any other labeled section. When a CONTROL BREAK statement executes, any previous CONTROL BREAK statement is overwritten so that only one is in effect at a time.

Use NOBREAK to restore the default behavior. NOBREAK clears the current CONTROL BREAK specification.

FSVIEW applications ignore this option.

HALTONDOTATTRIBUTE/NOHALTONDOTATTRIBUTE

HALTONDOTATTRIBUTE is in effect by default. If SCL detects an error in the dot notation used in your application, the application halts execution. If you specify NOHALTONDOTATTRIBUTE, the application will continue to execute when errors are detected in the dot notation, but the results will be unpredictable. See Accessing Object Attributes and Methods with Dot Notation for more information.

ENDSAS/NOENDSAS

NOENDSAS is in effect by default. When a user issues the ENDSAS or BYE command, the TERM sections of SCL programs in the current execution stack do not execute. This is called an ENDSAS event. Use CONTROL ENDSAS to force execution of the TERM section in an SCL program when an ENDSAS event occurs. ENDSAS has no effect on the _term method.

With NOENDSAS in effect, neither SUBMIT blocks nor SCL statements that call another entry are executed from the TERM section. Because the execution of a method or the setting of an attribute often involves calling another entry, you may find that updates to an object made from the TERM section are not executed.

ENDAWS/NOENDAWS

NOENDAWS is in effect by default. When a user ends a SAS session by selecting the system closure menu in a FRAME entry that is running with the Application Work Space (AWS), the TERM sections of SCL programs in the current execution stack do not execute. This is called an ENDAWS event. Use CONTROL ENDAWS to force execution of the TERM section in an SCL program when an ENDAWS event occurs. ENDAWS has no effect on the _term method.

With NOENDAWS in effect, neither SUBMIT blocks nor SCL statements that call another entry are executed from the TERM section. Because the execution of a method or the setting of an attribute often involves calling another entry, you may find that updates to an object made from the TERM section are not executed.

ENTER|NOENTER

NOENTER is in effect by default. The MAIN section executes only when a user modifies the value of a window variable and then presses either ENTER or a function key that is recognized by the procedure. Use CONTROL ENTER to force MAIN to execute when a user presses the ENTER key or a function key without modifying a window variable.

In FSVIEW applications, this option has an effect only if the cursor is on a valid row when ENTER or a function key is pressed.

ERROR|NOERROR

NOERROR is in effect by default. Statements in MAIN do not execute if a control or field contains a value that causes an attribute error. Thus, some statements in MAIN do not execute if multiple fields are in error and a user has not modified all of these fields. Use CONTROL ERROR to force statements in MAIN to execute even if the window contains fields that are in error.

If you use ERROROFF to remove the error status from a continued portion of a field in an FSEDIT application, then you must also use a CONTROL ERROR statement in the program. If a user does not type in the continued portion of the field and the program does not have a CONTROL ERROR statement, the error flag is not removed from the continued portion of the field. As a result, the default error message may be displayed, saying that a data value is not valid.

LABEL|NOLABEL

NOLABEL is in effect by default for PROGRAM and SCREEN entries. MAIN executes after any window variable is modified. Use CONTROL LABEL to force sections that are labeled with a window variable name (called window variable sections) to execute before MAIN executes. For FRAME entries, CONTROL LABEL is the default.

Statements in a window variable block execute after the associated window variable is modified, but only if the value does not introduce an error. That is, the value must satisfy any attributes that have been defined for the window variable.

Statements in MAIN do not execute until statements in all the window variable sections for modified fields execute successfully. The sequence for executing window variable sections is determined by the physical position of the field in the window from left to right and from top to bottom.

If a field modification introduces an attribute error, the associated window variable section does not execute. However, other window variable sections for modified window variables do execute. To correct an attribute error, you can allow users to correct the error in the window, or you can include SCL statements that make a correction in the labeled section for other fields.

If ERROR, ALWAYS, or ALLCMDS is also specified, then MAIN executes after the window variable sections even if an error was introduced.

If the window contains an extended table, the window variable section for each modified window variable executes for a row before the putrow section executes. MAIN executes after the putrow section executes.

Note:   If CONTROL LABEL is specified, a window variable section must not contain a SUBMIT IMMEDIATE block.  [cautionend]

TERM|NOTERM

This option is valid only for FSEDIT applications. NOTERM is in effect by default. Statements in the TERM section of FSEDIT applications do not execute when a user scrolls off the current row in a SAS table unless the user changed the values of one or more columns so that the current row needs to be updated in the table, or unless the row is new. Use the TERM option to force execution of the statements in the TERM section even if a user does not modify any columns in the current row.


Details

The CONTROL statement controls the execution of labeled program sections and also controls the formatting of code in a submit block. A CONTROL statement option remains in effect until another CONTROL statement option overrides it. Multiple CONTROL statement options can be in effect at the same time.


Examples


Example 1: Using the ASIS Option

Use the ASIS option:

control asis;
submit;
   data a;
      input x y z;
      datalines;
      10 20 30
      40 50 60
   run;
endsubmit;
rc=preview('display');

With the CONTROL ASIS statement in effect, the submit block executes without errors. If you remove the CONTROL ASIS statement, SCL formats the code within the block as follows when the code is submitted for processing:

data a;
input x y z;
datalines;
0 20 30 40 50 60 run;

When formatted in this manner, the final statement contains a syntax error and the code cannot execute properly.


Example 2: Controlling a Program Interrupt

Define a break handler section labeled STOPINIT. When a user interrupts processing while SCL statements in INIT are executing, the STOPINIT label executes. If the loop index I is less than 350, execution of the program halts and control returns to the calling program. Otherwise, execution resumes. After the first loop is finished, execute CONTROL NOBREAK so that there is no break handler. If a user interrupts processing during the second loop, the SCL Break window is displayed, and the statements in STOPINIT do not execute. The user can either abort or resume processing. Follow the same steps to define a new break handler section labeled STOPTERM in the TERM section.

INIT:
      /* define break label STOPINIT        */
   control break stopinit;
      /* loop 500 times to allow interrupt  */
      /* checking with control break        */
      /* if user interrupts, statements in  */
      /* label STOPINIT execute */
   do i=1 to 500;
      put i=;
   end;

      /* reset so there is no break handler */
   control nobreak;

      /* loop 500 times to allow interrupt  */
      /* checking without control break     */
   do i = 1 to 500;
      if (int(i/25) eq (i/25)) then put i=;
   end;
return;
MAIN: return;
TERM:
      /* Define the new break label STOPTERM. */
   control break stopterm;

      /* Loop 500 times to allow */
      /* interrupt checking with control */
      /* break.  If user interrupts,     */
      /* statements in label STOPTERM    */
      /* execute.                        */
   do j=1 to 500;
      put j=;
   end;

      /* Reset so there is no break handler.  */
   control nobreak;

      /* Loop 500 times to allow */
      /* interrupt checking without control  */
      /* break.                          */
   do j = 1 to 500;
      if (int(j/25) eq (j/25)) then put j=;
   end;
return;

STOPINIT:
      /* HALT if loop counter is less than 350, */
      /* otherwise RESUME.                      */
      /* Report the current status.             */
   put i=;
   if (i < 350) then
      _status_ = 'H';
   else
      _status_ = 'R';
return;

STOPTERM:
      /* HALT if loop counter is less than 350, */
      /* otherwise RESUME.                      */
      /* Report the current status.             */
   put j=;
   if (j < 350) then
      _status_ = 'H';
   else
      _status_ = 'R';
return;


See Also

WORD

Previous Page | Next Page | Top of Page