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?
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
>