%DO %UNTIL Statement

Executes a section of a macro repetitively until a condition is true.
Type: Macro statement
Restriction: Allowed in macro definitions only
See: %END Statement


%DO %UNTIL (expression);
text and macro language statements

Required Argument

can be any macro expression that resolves to a logical value. The macro processor evaluates the expression at the bottom of each iteration. The expression is true if it is an integer other than zero. The expression is false if it has a value of zero. If the expression resolves to a null value or a value containing nonnumeric characters, the macro processor issues an error message.
These examples illustrate expressions for the %DO %UNTIL statement:
  • %do %until(&hold=no);
  • %do %until(%index(&source,&excerpt)=0);


The %DO %UNTIL statement checks the value of the condition at the bottom of each iteration. Thus, a %DO %UNTIL loop always iterates at least once.

Example: Validating a Parameter

This example uses the %DO %UNTIL statement to scan an option list to test the validity of the parameter TYPE.
%macro grph(type);
   %let type=%upcase(&type);
   %let options=BLOCK HBAR VBAR;
   %let i=0;
   %do %until (&type=%scan(&options,&i) or (&i>3)) ;
      %let i = %eval(&i+1);
   %if &i>3 %then %do;
      %put ERROR: &type type not supported;
   %else %do;
      proc chart;&type sex / group=dept;
%mend grph;
When you invoke the GRPH macro with a value of HBAR, the macro generates these statements:
When you invoke the GRPH macro with a value of PIE, then the %PUT statement writes this line to the SAS log:
ERROR: PIE type not supported