LISTSERV at the University of Georgia
Menubar Imagemap
Home Browse Manage Request Manuals Register
Previous messageNext messagePrevious in topicNext in topicPrevious by same authorNext by same authorPrevious page (December 2006, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 20 Dec 2006 14:47:13 +0000
Reply-To:     toby dunn <tobydunn@HOTMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         toby dunn <tobydunn@HOTMAIL.COM>
Subject:      Re: Optional parameters in a macro
Comments: To: hirak99@GMAIL.COM
In-Reply-To:  <1166622824.110995.147480@i12g2000cwa.googlegroups.com>
Content-Type: text/plain; format=flowed

I will say you dont need commas nor anyother fancy macro junk at all, just a space separated list of values. Sinple and easy. Makes your job much easier, the code infinitly more readbale and usable and it means you can drop the positional parameter junk and use something useful like keyword parameters. There is so few cases where positional parameters can even be justified.

Toby Dunn

To sensible men, every day is a day of reckoning. ~John W. Gardner

The important thing is this: To be able at any moment to sacrifice that which we are for what we could become. ~Charles DuBois

Don't get your knickers in a knot. Nothing is solved and it just makes you walk funny. ~Kathryn Carpenter

From: abose <hirak99@GMAIL.COM> Reply-To: abose <hirak99@GMAIL.COM> To: SAS-L@LISTSERV.UGA.EDU Subject: Re: Optional parameters in a macro Date: Wed, 20 Dec 2006 05:53:44 -0800

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; > &sum; > %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.

_________________________________________________________________ Get free, personalized online radio with MSN Radio powered by Pandora http://radio.msn.com/?icid=T002MSN03A07001


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