/ Published in: SAS

3 examples
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) %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))
URL: http://support.sas.com/kb/25/961.html
Comments
