Sample 41754: Working with ARRAYs in PROC FCMP
In order to pass a group of variables in an ARRAY from a DATA Step to PROC FCMP to use when creating your function, you will have to create a TEMPORARY ARRAY in the DATA Step to pass the variable values. There is not a way to pass the group of variables in the ARRAY from the DATA Step to PROC FCMP without creating the TEMPORARY ARRAY. Passing TEMPORARY ARRAYS from a DATA step to PROC FCMP is the only time ARRAYS can be passed in BASE SAS.
Additional Documentation
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.
The goal is to illustrate how to pass a group of variables from the DATA step to PROC FCMP when creating a user defined function. To pass a group of variables from the DATA step to PROC FCMP, you must create 2 ARRAYS in the DATA step. One ARRAY will contain the variables you want to pass and the other ARRAY will be a TEMPORARY ARRAY. The TEMPORARY ARRAY is how you will pass the values from the DATA step to PROC FCMP. THe variables are passed to PROC FCMP using the TEMPORARY ARRAY reference on the FUNCTION statement in PROC FCMP. Then you can reference the group of variables like an array. In the example below a function is created using PROC FCMP which will total a group of variables and return the total to the DATA step when the function is called.
proc fcmp outlib=work.functions.samples;
function sas_summation (b[*]) varargs;
total = 0;
do i = 1 to dim(b);
total = total + b[i];
end;
return(total);
endsub;
run;
quit;
options cmplib=work.functions;
data one;
input x1-x5;
datalines;
1 2 3 4 5
2 3 4 5 6
4 5 6 7 8
;
run;
data two;
set one;
array temp (5) _temporary_;
array perm2 (*) x1-x5;
do i=1 to dim(temp);
temp(i)=perm2(i);
end;
drop i;
x=sas_summation(temp);
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 x
1 1 2 3 4 5 15
2 2 3 4 5 6 20
3 4 5 6 7 8 30
In order to pass a group of variables from a DATA step to PROC FCMP, you will have to create a temporary array to pass the variable values. Passing temporary ARRAYS from DATA step to PROC FCMP is the only time ARRAYS can be passed in BASE SAS.
Type: | Sample |
Topic: | SAS Reference ==> Procedures ==> FCMP
|
Date Modified: | 2010-12-15 16:23:49 |
Date Created: | 2010-12-06 11:02:58 |
Operating System and Release Information
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 | |
Windows Vista for x64 | 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 | |