What are packages for when using PROC FCMP?
PROC FCMP requires a three-level argument when specifying the output dataset in which the compiled function/subroutine should be stored. But when using those compiled functions SAS requires a two-level argument for the global option CMPLIB.
The documentation says:
Note: Subroutine and function names must be unique within a package. However, different packages can have subroutines and functions with the same names. To select a specific subroutine when there is ambiguity, prefix the subroutine name with the package name and a period (.) For example, to get the MthFncs version of inverse, use MthFncs.inverse
But I haven't been able to reproduce that behaviour. When doing:
proc fcmp outlib=work.functions.pkg1;
  function test(var1, var2); 
    return (var1+var2);
  endsub;
run;
proc fcmp outlib=work.functions.pkg2;
  function test(var1, var2);
    return (var1*var2);
  endsub;
run;
option cmplib=work.functions;
data _null_;
  a=test(3,3);
  b=pkg1.test(3,3);
  c=pkg2.test(3,3);
  put a= b= c=;
run;
The program crashes and says:
ERROR: DATA STEP Component Object failure. Aborted during the COMPILATION phase.
31    b=pkg1.test(3,3);
        _________
        557
ERROR 557-185: Variable pkg1 is not an object.
Isn't this the开发者_开发技巧 way packages are meant to be used? Am I doing something wrong? Looks like yes :) but I can't see what. Thanks!
It looks like the package.function() specification is only valid within proc fcmp at the moment and not within a data step. For example, this works (after creating the functions as you did):
proc fcmp;
  a=test(3,3);
  b=pkg1.test(3,3);
  c=pkg2.test(3,3);
  put a= b= c=;
run;
The following whitepaper says that there is no way to get a datastep to use same-named functions from multiple packages within a single datastep (page 15 under the heading "STORING AND SHARING FUNCTIONS"):
http://support.sas.com/resources/papers/proceedings09/147-2009.pdf
It does however provide some alternate suggestions.
Cheers Rob
PS - Make sure you check out runsubmit.com - It's just like stack overflow but just for SAS related questions.
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论