In this post, I will show you how to calculate the factorial of a given number using SAS Language.
Explain: For example, the factorial of 5 is equal to 5 x 4 x 3 x 2 x 1 = 120.
Using SAS Macro:
%macro factorial(num);
%local i result;
%let result = 1;
%do i = 1 %to #
%let result = %eval(&result * &i);
%end;
%put Factorial of &num: &result;
%mend;
SAS
itself provides a function that is fact to calculate the factorial of a number.
Using SAS fact function:
data _null_;
x = fact(5);
put "factorial is " x;
run;