Sample 35452: Calculating the product for a single variable or across variables
There is not a SAS statistic or function to calculate the product of a
variable or across variables. The sample below demonstrates this
technique for calculating the product of one variable.
/* create sample data */
data test;
input x @@;
cards;
1 2 3 8 9 21 11
;
run;
/* reshape the data */
proc transpose data=test out=out;
var x;
run;
data out;
set out;
array test(*) _numeric_;
prod=1;
do i=1 to dim(test);
prod=prod*test(i);
end;
drop i;
run;
proc print;
run;
To calculate the product for all numeric variables in a data set across
observations, the DATA OUT step above is all that is needed with the
appropriate data set name on the SET statement.
Below are two other SAS notes that also calculate the product.
SAS note 24628
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.
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.
Since reporting procedures, such as MEANS, SUMMARY, REPORT, and TABULATE, do not have a statistic to calculate a product, this type of calculation can be accomplished by reshaping the data and using ARRAY logic.
| Date Modified: | 2010-11-23 13:41:42 |
| Date Created: | 2009-04-03 13:46:14 |
Operating System and Release Information
| SAS System | Base SAS | Microsoft Windows Server 2003 Enterprise 64-bit Edition | | |
| Microsoft Windows Server 2003 Datacenter 64-bit Edition | | |
| Microsoft Windows XP 64-bit Edition | | |
| Microsoft® Windows® for x64 | | |
| OS/2 | | |
| Microsoft Windows 2000 Advanced Server | | |
| Microsoft Windows 95/98 | | |
| Microsoft® Windows® for 64-Bit Itanium-based Systems | | |
| z/OS | | |
| OpenVMS VAX | | |
| Microsoft Windows 2000 Datacenter Server | | |
| Microsoft Windows 2000 Server | | |
| Microsoft Windows 2000 Professional | | |
| Microsoft Windows NT Workstation | | |
| Microsoft Windows Server 2003 Datacenter Edition | | |
| Microsoft Windows Server 2003 Enterprise Edition | | |
| Microsoft Windows Server 2003 Standard Edition | | |
| Microsoft Windows XP Professional | | |
| Windows Millennium Edition (Me) | | |
| Windows Vista | | |
| 64-bit Enabled AIX | | |
| 64-bit Enabled HP-UX | | |
| 64-bit Enabled Solaris | | |
| ABI+ for Intel Architecture | | |
| AIX | | |
| HP-UX | | |
| HP-UX IPF | | |
| IRIX | | |
| Linux | | |
| Linux for x64 | | |
| Linux on Itanium | | |
| OpenVMS Alpha | | |
| OpenVMS on HP Integrity | | |
| Solaris | | |
| Solaris for x64 | | |
| Tru64 UNIX | | |