Return to Snippet

Revision: 63950
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);
    /* Just pass in starting and ending value */
    /** 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));
    /* Just pass in starting and ending value */

%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;
* %STR is used to mask the commas from the macro compiler when;
* the macro %LOOP is called.;

Initial URL

Initial Description
3 examples

Initial Title
Using character values on a macro %DO loop

Initial Tags

Initial Language