Create a macro variable named &VALUE that uses the %SYSEVALF function to re-
create the value as a non-integer. First subtract &START by &BY and then add that to
the product of &BY and &I.
%let value=%sysevalf(( &start - &by ) + ( &by * &i )) ;
Use the %IF statement to check that &VALUE from the %LET statement is less than or
equal to &END. If the condition is true, then place the value in the log using the %PUT
statement.
%if &value <=&end %then %do;
%put &value;
Use the %END statement to close both %DO loop blocks.
%end;
%end ;
%mend loop ;
Invoke the macro by using the start and end values of the loop as well as the increment
value.
%loop(start = 1 , end = 5 , by = .25 )
Example 4: How to Use Character Values on a
Macro %DO Loop
Details
The macro facility does not allow character values on an iterative %DO loop. There are
two macros below that give a work around to that limitation. These two macros use
different techniques to step through single-byte characters that are passed to the macro.
Program
Example 4A: This example enables you to step through only the characters that are
passed to the macro as a parameter to the macro variable named &LST.
%macro iterm(lst);
%let finish=%sysfunc(countw(&lst));
%do i = 1 %to &finish;
%put %scan(&lst,&i);
%end;
%mend iterm;
%iterm(a c e)
Example 4B: This example enables you to step through the characters between the
&BEG and &END values.
%macro iterm(beg,end);
%do i = %sysfunc(rank(&beg)) %to %sysfunc(rank(&end));
%put %sysfunc(byte(&i));
%end;
%mend iterm;
%iterm(a,e)
452 Appendix 5 • SAS Macro Examples