PROTO Procedure

Scope of Packages in PROC PROTO

PROC PROTO packages are loaded in the order that is specified in the CMPLIB option, and the contents are used globally. Packages that are loaded through a PROC statement option are considered local in scope. Local definitions are loaded last, and in all cases, local scope overrides global scope.
Definitions are loaded regardless of whether they have unique names or duplicate names. Multiple definitions of certain PROC PROTO elements (for example, enumeration names and function prototypes) can cause name conflicts and generate errors. To prevent name conflicts between PROC PROTO packages, ensure that elements such as enumerated types and function definitions have unique names.
The following example loads three PROC PROTO packages, and shows how the order in which typedef and #define statements override one another.
This part of the example loads the first two PROC PROTO packages:
proc proto package = work.p1.test1;
    typedef struct { int a; int b; } AB_t;
    #define NUM 1;
    int p1(void);
    externc p1;
        int p1(void)
        {
            return NUM;
        }
    externcend;
run;

proc proto package = work.p2.test2;
    typedef struct { int a; int b; } AB_t;
    #define NUM 2;
    int p2(void);
    externc p2;
        int p2(void)
        {
            return NUM;
        }
    externcend;
run;

options CMPLIB = (work.p1 work.p2);

proc fcmp;
   x = p1();
   put "Should be 2: " x=;
run;
The result from executing the programs above is 2, because the packages are loaded in order.
In the following example, PROC PROTO adds a third package and includes it in PROC FCMP locally, keeping the CMPLIB= system option set as above:
proc proto package = work.p3.test3;
    typedef struct { int a; int b; } AB_t;
    #define NUM 3;
    int p3(void);
    externc p3;
        int p3(void)
        {
            return NUM;
        }
    externcend;
run;

proc fcmp libname = work.p3;
   x = p1();
   put "Should be 3: " x=;
run;
In this example, the local definition of NUM in work.p3 is used instead of the global definitions that are loaded through work.p1 and work.p2.