# SAS Macro Examples - Control Structures

Last updated:

WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.

## Macro If then Else

%if ... %then %do;
...
%end;
%else %if ... %then %do;
...
%end;
%else %do;
...
%end;


## Macro do block

%do i = 0 %to &var %by 2;
...
%end;


## Do block with value ranges

do i = 1 to 3 , 8, 20;
put i= ;
end;


## Do-while block

loop testing is done at the top of the loop

do while ( <expression is true> );
...
end;


## Do-until block

loop testing is done at the bottom so the loop is always iterated at least once

do until ( <expression is false> );
...
end;