/***************************************************************************************************************** SAS file name: array_fcmp_argument.sas File location: __________________________________________________________________________________________________________________ Purpose: To demonstrate how to pass an array as an argument to functions and subroutines in PROC FCMP Author: Peter Clemmensen Creation Date: 17/01/2020 This program supports the blog post "Passing an Array as Argument in PROC FCMP" on SASnrd.com *****************************************************************************************************************/ /* Write a subroutine with an array as argument */ proc fcmp outlib=work.f.f; subroutine s (x [*]); outargs x; t = x [hbound(x)]; x [hbound(x)] = x [lbound(x)]; x [lbound(x)] = t; endsub; quit; options cmplib=(work.f); data _null_; array x {10} (1:10); call s (x); put (x[*])(=); run; /* The limitations of Dynamic_Array */ proc fcmp outlib=work.f.f; subroutine s (x [*]); outargs x; call dynamic_array (x, 1, 100); endsub; quit; /* Passing variable number of arguments is not the same as passing an array */ proc fcmp outlib=work.f.f; subroutine summin (t, x[*]) varargs; outargs t; t = 0; do i = 1 to dim(x); t = t + x[i]; end; endsub; call summin (t, 1, 2, 3); put t=; run; options cmplib=(work.f); data _null_; call summin (t, 1, 2, 3); put t=; run;