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 (August 2010, week 3)Back to main SAS-L pageJoin or leave SAS-L (or change settings)ReplyPost a new messageSearchProportional fontNon-proportional font
Date:         Wed, 18 Aug 2010 13:01:11 -0500
Reply-To:     Joe Matise <snoopy369@GMAIL.COM>
Sender:       "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From:         Joe Matise <snoopy369@GMAIL.COM>
Subject:      Re: Conditionally executing data step code in a macro?
Comments: To: mlhoward@avalon.net
In-Reply-To:  <20100818105313.68E4EE4E@resin11.mta.everyone.net>
Content-Type: text/plain; charset=ISO-8859-1

If it's not data-driven, then why not just %macro mymacro(groupcalmethod);

data datastep; %if &groupcalcmethod=method1 %then %do;

> group= (calculation for groupcalcmethod="method1"); > %end; %else %if &groupcalcmethod=method2 %then %do;

> group= {calculation for groupcalcmethod="method2"}; > %end;

> run; > > %mend; > ?

-Joe On Wed, Aug 18, 2010 at 12:53 PM, Mary <mlhoward@avalon.net> wrote:

> Question- what is a good way to pass a parameter to conditionally execute > code in a macro? I have two alternative calulations of the variable group > inside a data step in the macro (there's lots of other things in the macro): > > > group= (calculation) > > > And want to pass into the macro a parameter to indicate which calculation > to do: > > %macro mymacro(groupcalmethod); > > data datastep; > informat groupcalcmethod $40.; > groupcalcmethod="&groupcalcmethod"; > if strip(groupcalcmethod)='method1' then > group= (calculation for groupcalcmethod="method1"); > else if strip(groupcalcmethod)='method2' then > group= {calculation for groupcalcmethod="method2"}; > run; > > %mend; > > > %mymacro(method1); > > Please advise on the best approach to this, and whether the above syntax > needs changing. Right now there's only two methods, but there is a > potential for there to be three; I'd be interested in seeing different > approaches to this. > > -Mary >


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