Previous Page | Next Page

SAS Component Language Dictionary

CONTINUE



Stops processing the current DO loop and resumes with the next iteration of that DO loop
Category: Control Flow
Comparisons: SAS Statement with limitations in SCL

Syntax
Details
Example
See Also

Syntax

CONTINUE;


Details

The CONTINUE statement is provided in SCL to control the execution of DO loops. When you need to force the statements in a DO loop to stop executing, you can use the CONTINUE statement to stop executing successive statements in a DO loop, and to move back up and re-execute the DO loop, starting with the header statement.

Note:   In DATA step code, the CONTINUE statement stops processing only the current DO loop. In SCL code, the CONTINUE statement stops processing the current DO loop or DO group, whichever is closest. For example, suppose your code contains a DO loop that contains DO groups:

do n=1 to 5;     /* DO loop */
  if n=2 then do; continue; end;   /* DO group */
  put n=;
end;

When this code is compiled and run as part of an SCL program, the output is:

n=1
n=2
n=3
n=4
n=5

When this code is submitted as part of a DATA step, the output is:

n=1
n=3
n=4
n=5

See DO for more information on DO groups and DO loops.  [cautionend]

When you use DO WHILE and DO UNTIL statements, use caution to prevent the CONTINUE statement from forcing the program into an infinite loop. For example, the following statements produce an infinite loop because the value of the variable I never exceeds 2. When I has the value of 2, the IF statement always causes a branch around the next two SCL statements.
   /* This example causes an infinite loop */
INIT:
i=1;
do while (i<1000);
   if mod(i,2)=0 then
      continue;
   sum+i;
   i+1;
end;
return;

See the documentation for the CONTINUE statement in SAS Language Reference: Dictionary for more information.


Example

Count the number of females in the SAS table WORK.PERSONEL and display their average age. WORK.PERSONEL contains the column GENDER, which contains the values F for female and M for male, as well as the column AGE, which contains numeric values for age. The display window contains two numeric controls: AVGAGE and FEMALES. If the value of GENDER is not F (female), then the CONTINUE statement skips the other statements and returns to the DO WHILE statement to read the next row. The results are displayed in the application window, although the individual records are not displayed.

INIT:
   females=0;
   total=0;
   persnlid=open('personel');
   call set(persnlid);
  /* Process rows until all the */
  /* rows are read. */
   do while (fetch(persnlid) ne -1);
         /* Skip males when processing. */
      if gender ne 'F' then
         continue;
      females+1;
      total+age;
   end;
 /* Display the results in the fields */
 /* FEMALES and AVGAGE. */
      avgage=total/females;
return;
MAIN:
  ...other SCL statements...
return;

TERM:
   rc=close(persnlid);
return;


See Also

DO

LEAVE

Previous Page | Next Page | Top of Page