Sample 24628: Dynamically compute product of all values in an array
Use array processing to compute the product of multiple values.
Below are two other SAS notes that also calculate the product.
SAS note 35452
SAS note 41557
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.
/* Sample data set */
data a;
input x1-x5;
datalines;
1 2 3 4 5
2 3 4 5 6
4 5 6 7 8
;
data b;
set a;
/* Create an array with variables X1 through X5 */
array test(5) x1-x5;
/* Each value of the array is multiplied by PROD, which is */
/* initially set to the first array element */
do i=1 to dim(test)-1;
if i=1 then prod=test(i);
prod=prod*test(i+1);
end;
drop i;
run;
proc print;
run;
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.
Obs x1 x2 x3 x4 x5 prod
1 1 2 3 4 5 120
2 2 3 4 5 6 720
3 4 5 6 7 8 6720
Use array processing to compute the product of multiple values.
Type: | Sample |
Topic: | SAS Reference ==> DATA Step Data Management ==> Manipulation and Transformation ==> Array processing
|
Date Modified: | 2010-11-23 13:40:12 |
Date Created: | 2004-09-30 14:08:59 |
Operating System and Release Information
SAS System | Base SAS | All | n/a | n/a |