Date: Fri, 1 Dec 2006 10:46:15 -0500
Reply-To: Jeri Ji <jeri_ji@FREDDIEMAC.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Jeri Ji <jeri_ji@FREDDIEMAC.COM>
Subject: Re: Run macro based on some conditions
In-Reply-To: <BAY123-F208B8095E1FFFFF4E1E761DEDA0@phx.gbl>
Content-Type: text/plain; charset="US-ASCII"
Thank you very much for your advice. I AM very new to sas especially to
macro. However, it is very tempting to use macro since a set of code will
be run many times in a program. I am planning to take some classes on
macros and keep reading the emails regarding macros on sasl.
Thanks lot.
Jeri
"toby dunn" <tobydunn@hotmail.com>
11/30/2006 07:26 PM
To
jeri_ji@freddiemac.com, SAS-L@LISTSERV.UGA.EDU
cc
Subject
Re: Run macro based on some conditions
Jeri ,
I see you have gotten some great advice as ussual around here. If you are
knew around to SAS dont write macros until you have a better handle on the
data step language. Alot of people dont want to wait they just want to
jump
in and get going, however, this more often than not leads to more
confusion,
fear, and badly written macros than it is worth. While i dont know what
your macro does I can tell from just seeing the call that it has some
design
flaws. Something you will want to take care of.
Toby Dunn
Quickly, bring me a beaker of wine, so that I may wet my mind and say
something clever.
Aristophanes
Wise people, even though all laws were abolished, would still lead the
same
life.
Aristophanes
You should not decide until you have heard what both have to say.
Aristophanes
From: Jeri Ji <jeri_ji@FREDDIEMAC.COM>
Reply-To: Jeri Ji <jeri_ji@FREDDIEMAC.COM>
To: SAS-L@LISTSERV.UGA.EDU
Subject: Re: Run macro based on some conditions
Date: Thu, 30 Nov 2006 17:12:40 -0500
Thank you very much. This is exactly what I need. I tested it in my code
and everything worked. Since I am new to SAS and very new to macro, I
don't know what I can use to put in those conditions. I just know what I
need some condition and not output. So I thought about data _null_. I am
not surprise when you said that it didn't make any sense.
Thank you very much.
Jeri
Chang Chung <chang_y_chung@HOTMAIL.COM>
11/30/2006 05:02 PM
To
SAS-L@LISTSERV.UGA.EDU, jeri_ji@freddiemac.com
cc
Subject
Re: Run macro based on some conditions
On Thu, 30 Nov 2006 16:17:42 -0500, Jeri Ji <jeri_ji@FREDDIEMAC.COM>
wrote:
>I need to invoke a macro based on some conditions and my macro looks
like
>this:
>
>%let name_rpt=B;
>
>%macro run_rpt (rpt_name);
>.
>.
>.
>%mend run_rpt;
>
>And I wrote something like this:
>
>data _null_;
>if &name_rpt=B then do;
> %run_rpt(NATIONAL);
> %run_rpt(REGIONAL);
> end;
>else if &name_rpt=R then do;
> %run_rpt(REGIONAL);
> end;
>else %run_rpt(NATIONAL);
>run;
>
>But it won't work. Can somebody help please? Thanks.
Hi, Jeri,
So, you already have the macro %run_rpt, which expect either NATIONAL or
REGIONAL. And you were trying to write a wrapper. If you want a macro
wrapper, then write a macro wrapper. It does not make sense to use data
step
to write a macro wrapper. Something like below. HTH.
Cheers,
Chang
%macro run_rpt(rpt_name);
%put NOTE: from run_rpt with rpt_name=&rpt_name..;
%mend run_rpt;
%macro name_run_rpt(name=);
%if "&name." = "B" %then %do;
%run_rpt(NATIONAL)
%run_rpt(REGIONAL)
%end; %else %if "&name." = "R" %then %do;
%run_rpt(REGIONAL)
%end; %else %if "&name." = "N" %then %do;
%run_rpt(NATIONAL)
%end; %else %do;
%put ERROR:(name_run_rpt) name=&name. not allowed.;
%end;
%mend name_run_rpt;
/* tests */
%name_run_rpt(name=B)
/* on log
NOTE: from run_rpt with rpt_name=NATIONAL.
NOTE: from run_rpt with rpt_name=REGIONAL.
*/
%name_run_rpt(name=R)
/* on log
NOTE: from run_rpt with rpt_name=REGIONAL.
*/
%name_run_rpt(name=N)
/* on log
NOTE: from run_rpt with rpt_name=NATIONAL.
*/
%name_run_rpt(name=X)
/* on log
ERROR:(name_run_rpt) name=X not allowed.
*/
_________________________________________________________________
Get free, personalized commercial-free online radio with MSN Radio powered
by Pandora http://radio.msn.com/?icid=T002MSN03A07001