1. FACT function (was a very crude macro on calculating factorial..)
2. 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);
3. RE : Problem with macro: FACTORIAL
4. How to compare 2 crude rates from the same population
6. Calculating with macro values (ie comparing to a # in if/then st atement)
Venita, Could you show some examples of what does not work for you? Please include what is in the macro variable when it does not work. Your example of : %if &numzeros ne 0 %then %do . . . . . %end; should work as long as &numzeros contains numeric characters. The macro processor should automatically do an %eval on it. Regards, Dennis Diskin "DePuy, Venita" < XXXX@XXXXX.COM > wrote: Hi all - Hoping you can help me with an easy question that I just seem to be missing - I need to use a macro variable in some if/then calculations . . ie %if &numzeros ne 0 %then %do . . . . . %end; %if Probt le &alpha %then %do . . . %end; You get the idea. The obvious issue being that macro vars are character. I'm just not seeing a simple way to get them to numeric. Trying a input statement gave me an error (although it could be just me?) I've tried %eval statements, with no luck (some error about the operand not being present I think?) One solution I've found is %if (%substr(&numzeros,1,1) ne 0) %then %do . . . because numzeros is an integer, so if the first digit is zero, it's zero . . but I know that's not the best way. I've got several different versions of this in the program I'm writing (ie comparing a macro variable to a number) so thought the most efficient method would be to ask you all what I'm not seeing . . . Thanks much! Venita
7. Calculating with macro values (ie comparing to a # in if/then st atement)
8. Calculating with macro values (ie comparing to a # in if/the n st atement)