```Date: Wed, 20 Dec 2006 09:23:20 -0500 Reply-To: Gerhard Hellriegel Sender: "SAS(r) Discussion" From: Gerhard Hellriegel Subject: Re: Optional parameters in a macro To give it a frame: %macro ilist(start,end,step); %if &step= %then %let step=1; %if &end= %then %do; %let end=&start; %let start=1; %end; %do i=&start %to &end %by &step; &i %end; %mend; %put Results in %ilist(5); Regards, Gerhard On Wed, 20 Dec 2006 05:53:44 -0800, abose wrote: >Thanks all >@Gerhard Hellriegel: That was really cool, exactly what I was looking >for! > >What I actually need is a macro ILIST which will take max three >variables, and return a list like: >ILIST(5) --> 1 2 3 4 5 >ILIST(3,5) --> 3 4 5 >ILIST(1,5,2) --> 1 3 5 (third variable is step) > >Now I feel I can do it :) >Thanks a lot for helping! > >On Dec 20, 5:52 pm, gerhard.hellrie...@T-ONLINE.DE (Gerhard Hellriegel) >wrote: >> Perhaps like that: >> >> %macro sum(a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13); >> %let sum=0; >> %do i=1 %to 13; >> %if &&a&i= %then %let a&i=0; >> %let sum=%eval(&sum+&&a&i); >> %end; >> ∑ >> %mend; >> >> %put %sum(1,2,3); >> >> On Wed, 20 Dec 2006 04:21:37 -0800, RolandRB wrote: >> >abose wrote: >> >> Hi, >> >> Is there any way I can write a macro which will take optional >> >> parameters? For example, can I create something like a sum macro which >> >> works on 2 OR 3 variables: >> >> >> %sum(3,4) returns 7 >> >> %sum(3,4,5) returns 12? >> >> >Yes, use enough positional parameters to cover any usage of the macro. ```

Back to: Top of message | Previous page | Main SAS-L page