Note that there are some explanatory texts on larger screens.

plurals
  1. POConnect SAS to a C library
    primarykey
    data
    text
    <p>This is related to calling C functions (made into dynamic libraries) from SAS. There are 4 files. the first 2 (1 c-file and 1 sas-file) are a positive control using doubles. The remaining files are the problematic.</p> <p>C-FILE-1 </p> <pre><code>#ifdef BUILD_DLL #define EXPORT __declspec(dllexport) #else #define EXPORT __declspec(dllimport) #endif #include "stdio.h" #include "stdlib.h" #include "string.h" EXPORT void test (double *inarray, double *outarray, int n) { int i; for (i=0; i&lt;n;i++) { outarray[i]= inarray[i]*2; } return; } </code></pre> <p>//gcc -c -DBUILD_DLL pointersVoid.c<br> //gcc -shared -o pointersVoid.dll pointersVoid.o </p> <p>SAS-FILE-1 </p> <pre><code>filename sascbtbl catalog 'work.api.MYFILE'; data _null_; file sascbtbl; input; put _infile_; cards4; routine test module=pointersVoid minarg=3 maxarg=3; arg 1 input num byvalue format=IB4.; arg 2 input num byvalue format=IB4.; arg 3 input num byvalue format=PIB4.; ;;;; run; data test; array arr(5) _temporary_ (7.56 2.356 63.54 5.14 8.2); array ret(5); rc=modulen ("*e","test",addr(arr(1)), addr(ret(1)), 5); run; </code></pre> <p>This works fine and ret array now contains the *2 of the original values. But when we use strings we get errors:</p> <p>C-FILE-2 </p> <pre><code>#include "stdio.h" #include "stdlib.h" #include "string.h" char *strtrim_right(char *p) { char *end; int len; len = strlen(p); while (*p &amp;&amp; len) { end = p + len-1; if(isalpha(*end)) *end = 0; else break; len = strlen(p); } return(p); } EXPORT char **test (char **x, char **y, int n) { int i; for (i = 0; i &lt; n; i++) { y[i] = strtrim_right(x[i]); } } /* gcc -c -DBUILD_DLL pointers-array-string-void.c gcc -shared -o pointers-array-string-void.dll pointers-array-string-void.o */ </code></pre> <p>SAS-FILE-2 </p> <pre><code>filename sascbtbl catalog 'work.api.MYFILE'; data _null_; file sascbtbl; input; put _infile_; cards4; routine test module=pointers-array-string-void minarg=3 maxarg=3; arg 1 input char byvalue format=$CSTR200. ; arg 2 input char byvalue format=$CSTR200. ; arg 3 input num byvalue format=PIB4. ; ;;;; run; data test; array arr(5) $ _temporary_ ('PM23RO' '85AB12RE' 'RE147AMF' 'TAGH14MMF' 'LCA2Q'); array ret(5) $; call module ("*e","test",addr(arr(1)), addr(ret(1)), 5); run; </code></pre> <p>This doesn't work and gives errors:</p> <pre><code>Unrecognized option - in ROUTINE statement NOTE: Invalid argument to function MODULE ret1= ret2= ret3= ret4= ret5= rc=. _ERROR_=1 _N_=1 </code></pre> <p>I know the C-FILE-2 works well because the dll has been tested from another aplication, so ther error source is very likely the SAS code in SAS-FILE-2. Any suggestions to make it work?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload