I debated posting it, but was afraid it would clutter the thread. But since you ask, here goes...
I put together the sample VBA code below and ran it in Excel. You have to have SAS Integration Technologies client (standalone, or bundled with AMO and EG) installed on the machine to be able to add the required references to the SAS type libraries in the VBA editor in Excel. There are some help files (.chm) in the Integration Technologies installation folder that should provide some guidance on those interfaces.
Good luck!
Casey
Note: The sample uses the 9.2 interfaces, but I'd expect similar code to work in 9.1.3. The sample also connects to a server defined in metadata, but you should be able to change the code to connect to your local server if preferred.
============================
'Add reference to "SAS: Integrated Object Model (IOM)..." and "SASObjectManager ..." (optional)
Sub SubmitCodeTest()
Dim ws As workspace
Dim code As String
Dim log As String
Set ws = ConnectToServerUsingObjectFactory()
code = "data tmp; set sashelp.class; run;"
log = SubmitCode(ws, code)
MsgBox log
End Sub
Function ConnectToServerUsingObjectFactory() As workspace
On Error GoTo ErrHandler
'Requires reference to "SASObjectManager 1.1 Type Library"
Dim obObjectFactory As ObjectFactoryMulti2
'Requires reference to "SAS: Integrated Object Model (IOM) (SAS System 9.2) Type Library"
Dim obSAS As workspace
Dim obObjectKeeper As New SASObjectManager.objectKeeper
Set obObjectFactory = CreateObject("SASObjectManager.ObjectFactoryMulti2")
obObjectFactory.LogEnabled = True
' Use the SAS Object Manager to establish a SAS workspace object.
Set obSAS = obObjectFactory.CreateObjectByLogicalName("SASApp - Logical Workspace Server", "")
MsgBox obObjectFactory.GetCreationLog(False, True)
MsgBox obSAS.UniqueIdentifier
'Add the workspace to the object keeper
obObjectKeeper.AddObject 1, "", obSAS
Set ConnectToServerUsingObjectFactory = obSAS
Exit Function
ErrHandler:
MsgBox Err.Description
End Function
Function SubmitCode(workspace As workspace, code As String) As String
Dim ls As SAS.LanguageService
Dim logBuffer As String
Set ls = workspace.LanguageService
'if we submit asynchronously, we'd have to add a sink and wait to retrieve the log until signalled
ls.Async = False
ls.Submit code
'get the log
logBuffer = ls.FlushLog(100000)
'Could use FlushLogLines to get log instead
'Dim carriageControls() As LanguageServiceCarriageControl
'Dim lineTypes() As LanguageServiceLineType
'Dim logLines() As String
'ls.FlushLogLines 8192, carriageControls, lineTypes, logLines
'For Each line In logLines
' logBuffer = logBuffer & line & vbCrLf
'Next line
SubmitCode = logBuffer
End Function
Function AssignLibref(workspace As workspace, libraryName As String, path As String)
'Assign a libref using the DataService AssignLibref method...
workspace.DataService.AssignLibref libraryName, "", path, ""
End Function
... View more