The last time I wrote how to use VB with SAS, but VB is used to develop a high running efficiency. The system is not ideal. The following will introduce how to use VC to interact with SAS with SAS, only know the VC call COM Method and then refer to my blog's article, don't use me, I know, so "customer" in this article is a rookie programmer.
The first step, of course, introduced this COM type library, otherwise the VC compiler does not know your data type, so so .., import syntax
#import "c: / program files / sas / shared files / integration technology" above is the directory where your SAS type library is located.
In the second step, Microsoft tells me that to call COM must first initialize the COM environment, and finally the COM environment is currently cleared, so you have to write down the following code Coinitialize (null); / * N multi-Code in this intermediate * / ... Couninitialize The third step, of course, is an example of generating a COM object. The method of generating a COM object instance has N, but the following is the most easily, it is best to make first, to get a CLSID CLSID CLSID of COM object; CLSIDFROMPROGID (OLESTR ("SAS COM object, such as SAS.Workspace"); then, use this CLSID, you can generate an object through a smart pointer, as follows, ccomptr
class CSASPool {public: CComPtr
Then use the following code to call.
#include "stdafx.h"
#include
OVER, this code calls the last result will generate a 1.TXT file in your D. Then it will contain a word OK.
It's finished, but there is a special hidden bug that is included in the program, which is the use of the smart pointer.
As we all know, the smart pointer has encapsulated a perfect pointer, so that we don't have to pay attention to what - reference relationships.
but
Our intelligent pointer _sas life cycle is in
After Couninitialize (), the environment opened by Coinitialize is already in CounInitialize ().
Close, and _SAS, the sector occurs, may result in some problems, so so, the code called above is slightly changed, and it is good.
#include "stdafx.h"
#include
{CSASPool SAS = CSASPool (True, ClsID); Sas.exec ("Data _Null_; File 'D: //1.txt'; PUT 'OK'; Run;"); Sas.Close ();} Couninitialize () }
This time, it's true, there is nothing to say.