/ Published in: SAS
This sample contains 2 macro techniques for iterating through character values on a macro %DO loop.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* This macro will allow you to step through the lowercase letters of */ /* the alphabet on a %DO loop. For uppercase letters, edit the first */ /* %LET statement to include them as well. */ %macro iterm(beg,end); %let lst=a b c d e f g h i j k l m n o p q r s t u v w x y z; %let start=%sysfunc(indexc(%sysfunc(compress(&lst)),&beg)); %let finish=%sysfunc(indexc(%sysfunc(compress(&lst)),&end)); %do i = &start %to &finish; %put %scan(&lst,&i); %end; %mend; /* Just pass in starting and ending value */ %iterm(a,e) /** An alternative to the above example using the RANK and BYTE function **/ %macro iterm(beg,end); %do i = %sysfunc(rank(&beg)) %to %sysfunc(rank(&end)); %put %sysfunc(byte(&i)); %end; %mend; /* Just pass in starting and ending value */ %iterm(a,e)
URL: http://support.sas.com/kb/25/961.html