SAS Macro Examples - Control Structures
Last updated:Table of Contents
- Macro If then Else
- Macro do block
- Do block with value ranges
- Do-while block
- Do-until block
- Heads-up: If then Else
- Subsetting if
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;
Heads-up: If then Else
When data type numeric is used, zero and all missing values are false, and everything else is true.
Subsetting if
An if-statement without a then clause, preferably at the end of a data step.