Date: Thu, 6 Jan 2005 16:36:48 -0500
Reply-To: harry.droogendyk@RBC.COM
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Harry Droogendyk <harry.droogendyk@RBC.COM>
Subject: Re: Problem with macro: FACTORIAL
Content-Type: text/plain; charset=iso-8859-1
You're missing the %else on the %if.
Rather than fixing your macro, throw it out and use the FACT( ) function.
14 data _null_;
15 four = fact(4);
16 zero = fact(0);
17 put four= zero=;
18 run;
four=24 zero=1
-----Original Message-----
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU]On Behalf Of
Elmaache, Hamani
Sent: Thursday, January 06, 2005 4:24 PM
To: SAS-L@LISTSERV.UGA.EDU
Subject: Problem with macro: FACTORIAL
I'm trying to write this small macro:
calculate N! Example if N=4 we will have 1*2*3*4=24 =4!
The following macro very well when N is not zero, but when N=0 It doesn't
work.
Can someone help.
Thanks a lot.
%macro FACT(N=);
%*--------------------------------------------------------;
%* Return N! Example if N=4 we will have 1*2*3*4=24 =4! ;
%*--------------------------------------------------------;
data fac;
FACT=1;
%If &N=0 %then FACT=1;
%do I=1 %to &N;
FACT =FACT*&I;
%end;
proc print label;
var FACT;
run;
%mend FACT;
%FACT(N=4);
%FACT(N=0);
------------------------------------------------------------
This e-mail may be privileged and/or confidential, and the sender does not waive any related rights and obligations. Any distribution, use or copying of this e-mail or the information it contains by other than an intended recipient is unauthorized. If you received this e-mail in error, please advise me (by return e-mail or otherwise) immediately.
Ce courrier électronique est confidentiel et protégé. L'expéditeur ne renonce pas aux droits et obligations qui s'y rapportent. Toute diffusion, utilisation ou copie de ce message ou des renseignements qu'il contient par une personne autre que le (les) destinataire(s) désigné(s) est interdite. Si vous recevez ce courrier électronique par erreur, veuillez m'en aviser immédiatement, par retour de courrier électronique ou par un autre moyen.
============================================================