Use PROC FCMP to create a subroutine which is a cumulative product of a variable across observations in the SAS data set. User defined functions and subroutines created by PROC FCMP can be used in the DATA Step beginning in SAS 9.2.
For more information on PROC FCMP click on the link below to go to a 2007 SAS Global Forum paper about the procedure.
User-Written DATA Step Functions
Click on the link below to go to the SAS 9.2 documentation about PROC FCMP.
SAS 9.2 PROC FCMP Documentation
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.
/*Use PROC FCMP to create a SUBROUTINE which passes the value back to the DATA step
using the OUTARGS statement */
proc fcmp outlib=work.functions.samples;
subroutine sas_product(val, val2);
outargs val;
val=val*val2;
endsub;
run;
options cmplib=work.functions;
/* Sample data */
data one;
input x;
cards;
2
3
4
;
run;
/* Calling the subroutine created from PROC FCMP in the DATA step */
data two;
set one;
if _n_=1 then newx=1;
retain newx;
call sas_product(newx,x);
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 x newx 1 2 2 2 3 6 3 4 24
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> FCMP |
Date Modified: | 2010-12-03 10:06:29 |
Date Created: | 2010-12-02 11:00:51 |
Product Family | Product | Host | SAS Release | |
Starting | Ending | |||
SAS System | Base SAS | z/OS | 9.2 TS1M0 | |
Microsoft® Windows® for 64-Bit Itanium-based Systems | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise 64-bit Edition | 9.2 TS1M0 | |||
Microsoft Windows XP 64-bit Edition | 9.2 TS1M0 | |||
Microsoft® Windows® for x64 | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Datacenter Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Enterprise Edition | 9.2 TS1M0 | |||
Microsoft Windows Server 2003 Standard Edition | 9.2 TS1M0 | |||
Microsoft Windows XP Professional | 9.2 TS1M0 | |||
Windows Vista | 9.2 TS1M0 | |||
64-bit Enabled AIX | 9.2 TS1M0 | |||
64-bit Enabled HP-UX | 9.2 TS1M0 | |||
64-bit Enabled Solaris | 9.2 TS1M0 | |||
HP-UX IPF | 9.2 TS1M0 | |||
Linux | 9.2 TS1M0 | |||
Linux for x64 | 9.2 TS1M0 | |||
OpenVMS on HP Integrity | 9.2 TS1M0 | |||
Solaris for x64 | 9.2 TS1M0 |