Chapter Contents

Previous

Next
%DO %UNTIL

%DO %UNTIL



Executes a section of a macro repetitively until a condition is true

Type: Macro statement
Restriction: Allowed in macro definitions only
See also: %END


Syntax
Details
Example
Validating a Parameter

Syntax

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

expression
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:






Details

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

Example 1: 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);
   %end;
   %if &i>3 %then %do;
      %put ERROR: &type type not supported;
   %end;
   %else %do;
      proc chart;type sex / group=dept;
      run;
   %end;
%mend grph;

When you invoke the GRPH macro with a value of HBAR, the macro generates these statements:

PROC CHART;
HBAR SEX / GROUP=DEPT;
RUN;

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


Chapter Contents

Previous

Next

Top of Page

Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.