Sample 26172: Compute the factorial of a number
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
The FACT function computes the factorial of the given integer. The syntax is x=FACT(n) where n >= 0. If the expression cannot be computed, a missing value is returned.
/* In this example 6 is the supplied integer that represents the number of */
/* elements for which the factorial is computed */
data _null_;
x=fact(6);
put x=;
run;
/* Prior to Version 7 of SAS, you can use the GAMMA function to obtain the */
/* factorial of a number. For positive integers, gamma(x) is (x-1)! . For */
/* example, the following statement computes the factorial of 6: */
x=gamma(7);
These sample files and code examples are provided by SAS Institute
Inc. "as is" without warranty of any kind, either express or implied, including
but not limited to the implied warranties of merchantability and fitness for a
particular purpose. Recipients acknowledge and agree that SAS Institute shall
not be liable for any damages whatsoever arising out of their use of this material.
In addition, SAS Institute will provide no support for the materials contained herein.
/* The log displays the result from the PUT statement */
x=720
Use the FACT function to compute the factorial of the supplied integer.
| Type: | Sample |
| Topic: | SAS Reference ==> DATA Step SAS Reference ==> Functions ==> Mathematical
|
| Date Modified: | 2007-11-01 16:19:21 |
| Date Created: | 2007-07-06 12:50:32 |
Operating System and Release Information
| SAS System | Base SAS | All | 8 TS M0 | n/a |