Revision: 63950
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 20, 2013 19:14 by natsja
Initial Code
/* 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)
%macro loop(values);
* Count the number of values in the string;
%let count=%sysfunc(countw(&values));
* Loop through the total number of values;
%do i = 1 %to &count;
%let value=%qscan(&values,&i,%str(,));
%put &value;
%end;
%mend;
* %STR is used to mask the commas from the macro compiler when;
* the macro %LOOP is called.;
%loop(%str(2,3,5,7,11,13,17))
Initial URL
http://support.sas.com/kb/25/961.html
Initial Description
3 examples
Initial Title
Using character values on a macro %DO loop
Initial Tags
Initial Language
SAS