Date: Wed, 20 Dec 2006 05:53:44 -0800
Reply-To: abose <hirak99@GMAIL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: abose <hirak99@GMAIL.COM>
Organization: http://groups.google.com
Subject: Re: Optional parameters in a macro
In-Reply-To: <200612201252.kBKBkUWW029135@malibu.cc.uga.edu>
Content-Type: text/plain; charset="iso-8859-1"
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 <rolandbe...@HOTMAIL.COM> 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.
|