PROTO Procedure

Example: Splitter Function Example

Features:

INT statements

KIND= prototype argument

Other features:

PROC FCMP

Details

This example shows how to use PROC PROTO to prototype two external C language functions called SPLIT and CASHFLOW. These functions are contained in the two shared libraries that are specified by the LINK statements.

Program

options nodate pageno=1 linesize=80 pagesize=40;
proc proto package =
sasuser.myfuncs.mathfun
           label = "package of math functions";
                                 
           link "link-library";
           link "link-library";
   int split(int x "number to split")
       label = "splitter function" kind=PRICING;
   int cashflow(double amt, double rate, int periods,
                double * flows / iotype=O)
       label = "cash flow function" kind=PRICING;
run;
proc fcmp libname=sasuser.myfuncs;
   array flows[20];
   a = split(32);
   put a;
   b = cashflow(1000, .07, 20, flows);
   put b;
   put flows;
run; 

Program Description

Set the SAS system options. The NODATE option suppresses the display of the date and time in the output. PAGNO= specifies the starting page number. LINESIZE= specifies the output line length. PAGESIZE= specifies the number of lines on an output page.
options nodate pageno=1 linesize=80 pagesize=40;
Specify the catalog entry where the function package information is saved. The catalog entry is a three-level name.
proc proto package =
sasuser.myfuncs.mathfun
           label = "package of math functions";
                                 
Specify the libraries that contain the SPLIT and CASHFLOW functions. You can add more LINK statements to include as many libraries as you need for your prototypes.
           link "link-library";
           link "link-library";
Prototype the SPLIT function. The INT statement prototypes the SPLIT function and assigns a label to the function.
   int split(int x "number to split")
       label = "splitter function" kind=PRICING;
Prototype the CASHFLOW function. The INT statement prototypes the CASHFLOW function and assigns a label to the function.
   int cashflow(double amt, double rate, int periods,
                double * flows / iotype=O)
       label = "cash flow function" kind=PRICING;
Execute the PROTO procedure. The RUN statement executes the PROTO procedure.
run;
Call the SPLIT and CASHFLOW functions. PROC FCMP calls the SPLIT and CASHFLOW functions. Output from PROC FCMP is created.
proc fcmp libname=sasuser.myfuncs;
   array flows[20];
   a = split(32);
   put a;
   b = cashflow(1000, .07, 20, flows);
   put b;
   put flows;
run; 

OUTPUT: LISTING

                                           The SAS System                       
      1

                                         The FCMP Procedure

16
12
70 105 128.33333333 145.83333333 159.83333333 171.5 181.5 190.25 198.02777778
205.02777778
211.39141414 217.22474747 222.60936286 227.60936286 232.27602953 236.65102953
240.76867658
244.65756547 248.341776 251.841776