Introduction
Programmer is often asked which language can access SAS, which is the use of SAS IT mechanism, which allows development-style customers to access SAS, programmers can quickly establish strong applications with SAS interaction with different languages, this article main introduction How do you interact with SAS with VB?
Before reading
This article assumes that the reader has a certain understanding of the VB / COM / SAS knowledge.
SAS IT components
SAS IT is a middleware that provides users with access to SAS and presentation data, which contains the following features
1, LDAP (Lightweight Directory Access Protocol) directory integration
LDAP is an industrial standard for distributed storage data. Programmers can use Microsoft's ADSI (Dynamic Directory Services Interface) to access the LDAP directory, you can think of LDAP a database that can be accessed through TCP / IP, usually, one organization will have one Single LDAP server and shared by all machines of the organization
2, release / subscription
This positive information transfer mechanism enables you to make SAS output (publisher) to those who are interested in these outputs (subscribers)
This mechanism is an interface from IOM (integrated object model), SAS language call syntax and LDAP objects, and work together.
3, message queue
SAS can output the output information to the message queue so that the client does not have to wait for SAS execution to complete
Detailed use of the message queue for details:
http://www.sas.com/rnd/itech/doc/messageq/index.htm
4, IOM (integrated object model)
IOM is a collection of COM objects, most of which are usually used by VB.
SAS IT is better than the advantage of the OLE interface provided by previous versions.
IT is the extension of the previous OLE, the following is more mainly different.
1, IT provides a multi-level interface, while OLE only provides a single interface
2, IT is a cross-platform (platform that SAS can support, such as Win / UNIX / OS, etc.), VB applications can call IT objects through the far end, while OLE can only run in Win platform
3, IT object allows SAS programs to run asynchronously, and OLE can't
Note: The root object of the IT object is "Sas.Workspace", which corresponds to the "SAS.Application" object of the OLE.
VB programmer's IT tool
Contains IOM, SAS Workspace Manager, IOM Data Provider, IOM Bridge for COM, SCRIPTO
IOM
The client can connect to the IOM server through a variety of connections, such as CORBA / JDBC / COM / OMG, and no need to attach the code to the client.
IOM is an object model because it exposes a set of objects for users.
These objects can be used to implement two goals: submit code to SAS and obtain SAS output
In the IM object, the array is widely used, so all requests are returned at the same time.
What you want is: If there is no SAS IT product authorization, the IOM interface can only be used by local COM. If there is authorization, you can access the remote IOM interface through the network.
The root object at the IOM object level is Workspace, each such object has its own work library
The Workspace object provides the objects available below
DataService object: Returns an interface to an SAS library, which also provides an interface to read and write SAS data, but the VB programmer cannot be used directly, only indirectly by SAS data provider.
FILESERVICE object: Returns a connection to the SAS server file and file reference
GetApplication Object: Returns a custom interface with SAS / AF
LanguageService object: Returns a file submitted SAS code and gets the output
IOM usage example
Suppose the following code has been executed
Dim obwsmgr as new _sasworkspacemanager.WorkspaceManager
DIM OBSAS As Sas.Workspace
DIM XMLINFO As String
'This Creates a Sas Server Running on The
'Local Machine
Set obsas = Obwsmgr.Workspaces.createWorkspaceByserver (", Visibilitynone, Nothing,", ",", XMLInfo)
Example 1: Submit code
There are two ways to submit code to SAS Server
Way 1: Use LanguageService
Obsas.LanguageService.Submit_
"DATA A; Do X = 1 to 10; y = x * x * x;" & _
Output; end; run; "
Msgbox Obsas.LanguageService.flushlog (100000)
Way 2: Using StoredProcessService
This method requests the SAS file to store in a known directory, and can pass parameters to file through the macro, and in the SAS file, you want to receive parameter information, you need such syntax:
* Processbody;
It will automatically convert incoming parameters to macro
If there are multiple parameters, use [space] to separate when it is incorporated
E.g:
'Run The Sas Program At C: /Temp/looper.sas
DIM OBSTOREDPROCESSERVICE AS _
Sas.StoredProcessService
Set obstoredProcessService = _
Obsas.languageService.StoredProcessService
ObstoredProcessService.Repository = _
File: C: / Temp
ObstoredProcessService.execute "looper", _
"LoopTimes = 10"
Msgbox Obsas.LanguageService.flushlog (100000)
The content of the looper.sas file is as follows:
% let looptimes = 3;
* Processbody;
Data A;
Do x = 1 to & looptimes;
Y = x * x * x;
OUTPUT;
END;
Run;
Example 2: Execute code
Async Attribute: If false, execute in synchronization, no, for asynchronous execution, you can get successfully performed through the event
Define an error occurred below:
Public Withevents obsaslanguage as _ Sas.LanguageService
'TO Enable Events, You Must Associate THE
'Obsaslanguage
'Interface with The Same LanguageService
'interface use to make calls.
Set Oblanguage = Obsas.LanguageService
Oblanguage.submit "this is an error; run;"
Private sub oblanguage_steperror ()
'An error has occurred. Dump the logdebug.print Oblanguage.flushlog (100000)
End Sub
Example 3: Get an output
SAS will output multiple types of information for users, as follows
IOM Data Provider provides binary data access to users
LanguageService's flushlist flushlistLines method can get the window output of SAS
If you want to get an ODS output, you can use the FileService provided by the file to provide such services.
The following demonstrates how to get the output of the FileService mode
Dim ObfileRef as Sas.Fileref
DIM ObtextStream as Sas.TextStream
Dim Obfilesystem as new scripting.FileSystemObject
Dim Obfile as scripting.textStream
Set Obfile = Obfilesystem.createTextFile ("C: /Temp/sASoutput.htm", True)
Obsas.LanguageService.Submit "Filename Fref Temp;" & "ODS HTML BODY = FREF;" & "Proc Corr Data = Sashelp.class;" & "Run;" & "ODS HTML Close;"
Set Obfileref = Obsas.FileService.usefileRef ("FREF")
Set ObtextStream = ObfileRef.opentextStream (StreamopenModeforReading, 10000)
Sodsoutput = ObtextStream.read (100000)
While (Len (Sodsoutput)> 0)
'Do Something with The Read Text Here
Obfile.write Sodsoutput
Sodsoutput = ObtextStream.read (100000)
Wend
WebBrowser1.naviGate "c: /temp/sasoutput.htm"
In fact, there is no need to do this in a stand-alone environment :)
You can also get the output using ResultPackageService, which can be referenced by Workspace.Utilities.ResultPackageService
You can build ResultPackage with the interface provided by ResultPackageService, of course, can also pass the SAS language Call syntax.
A ResultPackage can be any SAS output, such as files, datasets, ODS outputs, pictures, etc.
The following example shows how to create a ResultPackage
% Macro Checkrc (RC);
IF rc NE 0 THEN DO;
Msg = sysmsg ();
PUT MSG;
Abort;
END;
% mend;
Data _null_;
Call Package_Begin (PID, DESC, NAMEVAL, RC);
% Checkrc (RC);
Call INSERT_FILE (PID, 'FileRef: Fref',
"Text", "text / html", "some ods output",
'', RC);
% Checkrc (RC);
/ * Nothing in the package actual gets
* Written Out UnTil We Call Publish.
* So, if you modify Any FileRefs After
* Calling Insert But Before Calling
* this, thr
* Modified FileRef. * /
Call package_publish (PID, "To_archive", RC,
"Archive_Path, Archive_Name", "C: / Temp",
"archive");
% Checkrc (RC);
/ * You Could Call Package_Publish As Many
* Times as you want for any given package,
* As long as you
* Do So Before Calling package_end. * /
Call package_end (pid, rc);
% Checkrc (RC);
Run;
How do you read this resultPackage?
Dim props () AS STRING
Dim obethultpackage as sas.ResultPackage
Dim ObfileEntry As Sas.ResultPackageFileEntry
Dim obrps as Sas.ResultPackageService
Set obrps = obsas.utilities.ResultPackageService
Set ObResultPackage = Obrps.BrowseresultPackage ("Archive", "C: /Temp/archive.spk", PrOPS)
Set ObfileEntry = ObResultPackage.GeTENTRY (0)
Set ObtextStream = ObfileEntry.Open (streamopenmodeforreading, 100000)
Sodsoutput = ObtextStream.read (100000)
While (Len (Sodsoutput)> 0)
'Do Something with The Read Text Here
Obfile.write Sodsoutput
Sodsoutput = ObtextStream.read (100000)
Wend
WebBrowser1.naviGate "c: /temp/sasoutput.htm"
About SAS Workspace Manager
It is an ActiveX control that completes the following functions
1, it is connected to SAS and return to work space
2. It provides a pool to ensure that each workspace is safe in a web environment.
3, automatically keep the connection with SAS
You can establish a connection with SAS using the following two ways
Non-managed mode (all connection information is kept at the client)
Managed mode (so connection information is retained in file or LDAP)
These connection information contain which machine connected to, what protocol, what port or service name, username, user ID, etc., while DCOM or IOM support encrypted session
Example 1: Establish a connection, non-managed mode
DIM OBWSMGR AS New_
Sasworkspacemanager.WorkspaceManager
DIM OBSAS As Sas.Workspace
DIM XMLINFO As String
DIM OBSERVER AS New_
Sasworkspacemanager.serverdefobserver.machinednsName = "remote.sas.com"
Set obsas = _
Obwsmgr.workspaces.createworkspaceByServer_
("" "", Visibilitynone, observer, "", "", _
XMLinfo)
XMLINFO parameter returns the value used by the server actually used
About IOM Data Provider
IOM Data Provider is an OLE DB of OLE DB using IOM DataService.
You can read and write data using ADO
E.g:
Set obsas = _
Obwsmgr.workspaces.createworkspaceByServer_
("" "" "" "" "" "," ", _
XMLinfo)
DIM Obconnection As New Adodb.Connection
Obconnection.open_
"provider = sas.iomprovider.1;" & _
"SAS Workspace ID =" & obsas.UniqueIndentifier
DIM obrs as new adod.com.recordset
Obrs.open "Sashelp.class", Obconnection, _
AdoPendynamic, AdlockReadonly, _
AdcmdtableDirect
Set mschart1.datasource = OBRS
About IOM COM Bridge
When SAS runs on Window, you can use COM or DCOM, however, when SAS is running on UNIX or OS, you cannot use COM technology to call SAS. SAS provides an IOM COM bridge, which is convenient to present COM interface to the client, On the one hand, use TCP / IP to communicate with SAS
About SCRIPTO
Scripto is an AcitVeX object for scripting applications that solves several restrictions to interact with SAS component objects. If VBScript can only return a single parameter; VBScript requests all variables to be variant, so the ancestors are also processed as Variant, Scripto resolves these two questions, allowing multiple parameters to be returned, you can use arrays to transfer
'Scripto Will Do 2 Things:
'1) IT Will Convert The 3 Returned Arrays to Arrays of Variants INSTEAD OF ARRAYS OF
'Longs So Vbscript Can Handle THEM
'2) IT Allows More Than 1 Return Parameter
Set obsas = creteObject ("Sas.workspace")
Set obscripto = _
CreateObject ("Sasscripto.scripto")
Obsas.LanguageService.Submit_
"Proc Options; Run;"
Obscripto.setInterface obsas.languageService
'obsas.languageservice.flushloglines 1000, CarriageControls, LineTypes, Loglines
Dim flushloglinespamas (3) FlushloglinesParams (3) = 1000
Obscripto.invokemethod "flushloglines", _
Flushloglinesparams
'Flushloglinesparams (0) Now Has Loglines
'Flushloglinesparams (1) HAS LineTypes
'FlushloglinesParams (2) HAS CarriageCtrls
'This Prints the first line
Wscript.echo flushloglinesparams (0) (0)
About IT client
You need to install and register a few files on the client
The IT client's necessary file is automatically installed, by calling IntTech.exe, which will install the necessary files over the network