2010-02-25 36 views
3

我一直戳我在擴展SAS字符串一些C函數處理鼻子的C函數,如最長公共子算法。 proc FCMP函數變得非常低效。傳遞字符串與SAS PROC原

在PROC原嵌入式C編譯器似乎並不在Visual Studio編寫算法後,產生我所期望的結果。有一兩件事我想我已經證實的是,傳遞給C函數的字符串似乎要被填充爲大約100個字符的長度空間。

我去之前就編寫更多的代碼,以推斷該字符串應該結束的地方,我想知道,如果有人知道的替代方法或可以在大約寫C函數SAS普通股的想法?

下面是一些代碼爲例

/* C functions*/ 
proc proto package=sasuser.funcs.sfuncs; 
    /* A string length function */ 
    int cslen(const char *s); 
    externc cslen; 
    int cslen(const char *s) 
    { 
     int i=0; 
     while (s[i++]!=0){} 
     return i-1; 
    } 
    externcend; 
    /* A char function */ 
    int cschar(const char *s,const int pos); 
    externc cschar; 
    int cschar(const char *s,const int pos) 
    { 
     return s[pos]; 
    } 
    externcend; 
run; 
option cmplib=sasuser.funcs; 
/* SAS wrappers */ 
proc fcmp outlib=sasuser.funcs.sfuncs; 
    function slen(s $); 
     val=cslen(s); 
     return(val); 
    endsub; 
    function schar(s $,pos); 
     val=cschar(s,pos); 
     return(val); 
    endsub; 
quit; 

測試funcs中與

/* Tests */ 
data _null_; 
    length str $6.; 
    str="foobar"; 
    len=slen(str); 
    firstchar=schar(str,0); 
    lastchar=schar(str,5); 
    shouldbenull=schar(str,6); 
    put _all_; 
run; 

str=foobar len=91 firstchar=102 lastchar=114 shouldbenull=32 _ERROR_=0 _N_=1 

編輯:我們,事實證明,你可以通過簡單地修改包裝中的字符串來解決這個問題例如:

proc fcmp outlib=sasuser.funcs.sfuncs; 
    function slen(s $); 
     val=cslen(trim(s)); 
     return(val); 
    endsub; 
quit; 

回答

3

我會聯繫SAS技術支持([email protected])以獲取PROC PROTO的幫助以及SAS如何將字符串傳遞到C例程中。

還有其他的方法來訪問C語言編寫的一個是使用呼叫模塊,該MODULEN功能或MODULEC功能程序。這些例程可以調用存儲在.dll(或Unix上的.so)中的函數。到Windows CALL模塊文檔的鏈接是在這裏:

http://support.sas.com/documentation/cdl/en/hostwin/61924/HTML/default/win-func-module.htm

鏈接到UNIX CALL模塊文檔是在這裏:

http://support.sas.com/documentation/cdl/en/hostunx/61879/HTML/default/unx-func-module.htm

另一種選擇是許可SAS /工具包。 SAS/Toolkit允許你寫的功能,特效,格式,informats,和發動機的C,和其他語言,可以從SAS可以使用。這裏是有關SAS/TOOLKIT信息的頁面:

http://www.sas.com/products/toolkit/index.html

+1

Thanks,+1。爲了可移植性和代碼控制,我實際上更喜歡在SAS中編譯小函數,而不是依賴於DLL。 – 2010-03-03 05:46:17