1

I want to use proc fcmp to define my own function in SAS9.3. OS is aix 64bit. Here is my code (reg_func.sas):

proc fcmp outlib=mylib.funcs.rule;
function gen_sub_rule();
put "this is a test function";
return (0);
endsub;
run;
quit;

but after run sas reg_func.sas, i got some warnings

WARNING:Cannot wirte model to data set mylib.funcs because it is curently opened or already exists as a standart data set.Will revert to V8 CATALOG instread. WARNING:Failed to save function gen_sub_rule to mylib.funcs.rule.

Can anyone help?Thanks!

  • Have you tried a different outlib option? – Reeza Apr 27 '16 at 03:58
  • @Reeza, Thanks, I tried this way, add [libname mylib '/home/ap/sas/mydir';] before my proc fcmp code. and it works. but there is another problem.,when i use deletefunc, sas tells this waning:SUBROUTINE 'GEN_SUB_RULE' cannot be found for deletion. – heirish lee Apr 27 '16 at 07:31
  • Post how you tried to delete it. Without seeing code only assumption is you did something wrong :) – Reeza Apr 27 '16 at 09:44
  • @Reeza, Here is my delete code:`proc fcmp outlib=mylib.funcs.rule; deletefunc gen_sub_rule;run;quit;` – heirish lee Apr 27 '16 at 15:15
  • It's a warning, not an error. I'm not sure how to get rid of it. Is your function actually deleted? – Reeza Apr 28 '16 at 17:53
  • @Reeza, No, my function wasn't deleted.it still exists in `mylib.funcs.rule`.i think ith's kind of strange that sas can't find my funcion.Maybe there is something wrong with my sas configuration, i changed my plan to use macro in my proj. thanks ,it's very kind of you of answering my question. – heirish lee Apr 29 '16 at 02:48
  • You should post it on communities.sas.com, someone way more knowledgeable than me will answer it. – Reeza Apr 29 '16 at 04:13
  • @Reeza, Yeah, i will try that, Thanks – heirish lee May 04 '16 at 07:14

1 Answers1

1

Solved! Referrring to https://communities.sas.com/t5/Base-SAS-Programming/Irritating-warning-in-Proc-FCMP/td-p/16216
The key is the cmplib option, here is my code:

    libname mylib 'H:\saslib\testlib';
    proc fcmp outlib=mylib.funcs.rule;
      function calc(var);
         newvar=log(var);
         return(newvar);
      endsub;
     function gen_str(var1 $, var2 $, var3 $) $100;
        length newvar $100;
        newvar=catx('#', var1, var2, var3);
        return(newvar);
      endsub;
    Run;

    /*list the source code*/
    Options cmplib=_null_; 
    proc fcmp library=mylib.funcs;
      listfunc calc gen_str;
      run;
    Quit;

    /*using func*/
    options cmplib=mylib.funcs; 
      data _null_;
        numret=calc(20);
       charret=gen_str('what', 'is', 'your');
       put numret= charret=;
    run;

    /*delete the func*/
    options cmplib=mylib.funcs; 
    proc fcmp outlib=mylib.funcs.rule;
    deletefunc calc;
    run;
    quit;