Examples of Automating SAS with OLE


The following examples use Visual Basic as the scripting language to control SAS with OLE automation. You can use any scripting language from any Windows application that can act as an OLE automation controller.

Creating a SAS Automation Object

This Visual Basic code defines an object and creates an instance of SAS to associate with that object.

 Dim OleSAS As Object  Set OleSAS = CreateObject("SAS.Application") 

Determine Whether the SAS Session is Busy

This Visual Basic code queries the SAS session (using the Busy property) to test whether the session is busy processing code.

 If (OleSAS.Busy) Then     Response = MsgBox("SAS Session is Busy",                vbOKOnly, "SAS Session", 0, 0)  Else     Response = MsgBox("SAS Session is Idle",                vbOKOnly, "SAS Session", 0, 0)  End If 

Toggle the SAS Session between Visible and Invisible

This Visual Basic code hides or unhides the SAS session based on its current state.

 OleSAS.Visible = false 

Set the Main SAS Window Title of the SAS Session

This Visual Basic code assigns a title to the main SAS window of the SAS session and then displays the title in a message box.

 OleSAS.Title = "Automation Server"  Response = MsgBox(OleSAS.Title, vbOKOnly,             "Title Is", 0, 0) 

Assign a SAS Data Library and Run a SAS Procedure

This Visual Basic code submits SAS code to the SAS session, assigning a SAS data library and running the INSIGHT procedure on sample data.

 OleSAS.Submit("libname insamp                  'c:\sas\insight\sample';                 proc insight data=insamp.drug;                 run;") 

End the SAS Session

This Visual Basic code ends the SAS session provided that there are no other OLE automation controllers making use of it.

 OleSAS.Quit  Set OleSAS = Nothing 



SAS 9.1 Companion for Windows
SAS 9.1 Companion for Windows (2 Volumes)
ISBN: 1590472004
EAN: 2147483647
Year: 2004
Pages: 187

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net