Hi Chang, thanks for the reply but... Non nesting the macro would imply renaming all invocations of %macr to %doOver (your suggestion), while nesting it will allow you to keep the original name. That's really why I've nested the macro and renamed the parent to the original name. As for the recursiveness, I believe what I've showed can't be considered recursive, as there is no recursive feedback from the macro to the previous iteration. But I get your point, self-calling the macro just obfuscates the coding, which I really don't like it, also it reminded me what was my mindset at the beginning which I guess I lost on the way. Thank you for pointing that. So here's the "revisited" code, shorter, polished and truly recursive which allows any form of mixed var list and ranges: (<X1 X2 ... XN>|<Y1-YN>)* %macro macr(VARLIST); * expands range recursively; %macro expand(VARLIST); %if %index(%str(&VARLIST),%str(-)) %then %do; %let PRX=%sysfunc(prxparse(s!(([_A-Z]+\d+\s+)*)([_A-Z]+)(\d+)[-]{1}([_A-Z]+)(\d+)!$3 $4 $6|$1!i)); %let PRX=%sysfunc(prxchange(&PRX,1,&VARLIST)); %macro VARLIST; %do _I=%scan(&PRX,2) %to %scan(&PRX,3);%scan(&PRX,1)&_I%str( )%end; %mend VARLIST; %sysfunc(compbl(%VARLIST%expand(%scan(&PRX,2,%str(|))))) %end; %else %str(&VARLIST); %mend expand; * single macro var code here; %macro _macr(VAR); %put _macr(&VAR); %mend _macr; * single macro var code here; %let VARLIST=%expand(&VARLIST); %do _I=1 %to %sysfunc(countc(&VARLIST,%str( )))+1; * iterate through var list; %_macr(%scan(%str(&VARLIST),&_I,%str( ))); %end; %mend macr; * so now, everything is possible; %macr(X1-X10); %macr(X1-X10 Y1-Y5); %macr(X1-X10 Y1 Y3 Y6 Y8 Y9); %macr(X1 X3 X6 X8 X10 Y1-Y5); %macr(X1 X4 Y1-Y5 X5 X10); %macr(X1 X3 X4 X7 X10); Thanks for the reply. Cheers from Portugal. Daniel Santos @ www.cgd.pt
... View more