Statistical programming, matrix languages, and more

C based SAS routine in IML

Reply
Occasional Contributor
Posts: 6

C based SAS routine in IML

[ Edited ]

Hello everyone,

I use a C code to create a subroutine (using proc proto and proc fcmp). The problem is that it uses a vector as a parameter and creates a vector as a result. This looks problematic in data step of BASE SAS, but I thought SAS IML might work out way better. Does anyone have a clue how to use a SAS routine in SAS IML? Or anyone knows a way how to make this work in a data step?

 

Thank you!

SAS Super FREQ
Posts: 3,615

Re: C based SAS routine in IML

I've never done this in PROC IML, but I have three comments:

1) SAS/IML uses the MODULEI (return void), MODULEIN (return number), and MODULEIC (return char) subroutines to call DLLs that contain C functions.  You can pass in vector and matrices for arguments.If you mark an argument as 'update', then the C routine can change the values of the argument (like passing a pointer).   I think this is what you want to do.

2) Although I have never done (1),  I have called C DLLs from the SAS/IML Studio application, which has a much simpler system for calling DLLs. See the documentation for "Extending IML"-->"UIsing C" at http://support.sas.com/documentation/onlinedoc/imlstudio/WebHelp132/root.htm

3) I have found that well-written vectorized IML code is almost as fast as C code for many applications. You might want to post what you are trying to accomplish. Someone might have IML code that does it already.

Occasional Contributor
Posts: 6

Re: C based SAS routine in IML

[ Edited ]

Thank you Rick,

I would like to calculate poisson binomial distribution cdf.
Actualy this is one topic : https://communities.sas.com/t5/SAS-Statistical-Procedures/Poisson-binomial-distribution-in-SAS/m-p/2...

 

ps. Unfortunately step 2 will not work for us because not always might use client Windows PC.

 

 

SAS Super FREQ
Posts: 3,615

Re: C based SAS routine in IML

Hmm, not for the faint of heart!  Have you looked at the FFT function in SAS/IML?  I think IML has the building blocks that you need, but that's not a trivial computation.   I do not know which method would be easier: calling a C routine or rewriting in IML.  I guess if you have a working and debugged C routine, that is the method you should try first, but I am not finding any good examples that lay out all the steps for calling C functions from PROC IML.  I guess you'll have to use the examples for the DATA step versions such as CALL MODULE.

 

Ask a Question
Discussion stats
  • 3 replies
  • 443 views
  • 0 likes
  • 2 in conversation