Use SAS Bridge for Esri objects in a custom application
The following three sample macros export Esri data to a SAS data
set:
You can paste the samples into the Visual Basic Editor in ArcMap.
Export All Attributes to SAS
Sub ExportAllAttributesToSAS()
Dim SASds As New SASBridge.AttribDataSet
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFeatLayer As IFeatureLayer
Dim pDisplayTable As IDisplayTable
Dim pTable As ITable
Dim pFeatCursor As IFeatureCursor
Dim pFeatSelection As IFeatureSelection
Dim pSelection As ISelectionSet
Dim SASServer As New SASBridge.server
Dim Connection As New SASBridge.IOMConnection
'Start the SAS server with null connect string. This will start a
' local sas server.
Connection.ConnString = ""
Set SASServer.Connection = Connection
If (Not SASServer.StartSAS()) Then
MsgBox "Failed to start the SAS server, terminating export."
Exit Sub
End If
'Get the table from the layer to export
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pFeatLayer = pMap.Layer(1)
Set pDisplayTable = pFeatLayer
Set pTable = pDisplayTable.DisplayTable
'Set the export properties
Set SASds.Workspace = SASServer.Workspace
Set SASds.Table = pTable
SASds.DSName = "SASUSER.Layer1"
SASds.Append = False
If (Not SASds.ExportAll(SASServer, Application)) Then
MsgBox (SASds.ErrorMsg + " Export failed.")
End If
If (Not SASServer.stopSAS()) Then
MsgBox "Unable to terminate the SAS server."
End If
End Sub
|
Export Selected Attributes to SAS
Sub ExportSelectedAttributesToSAS()
Dim SASds As New SASBridge.AttribDataSet
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pFeatLayer As IFeatureLayer
Dim pDisplayTable As IDisplayTable
Dim pTable As ITable
Dim pFeatCursor As IFeatureCursor
Dim pFeatSelection As IFeatureSelection
Dim pSelection As ISelectionSet
Dim SASServer As New SASBridge.server
Dim Connection As New SASBridge.IOMConnection
'Start a remote SAS Server.
Connection.ConnString = "Data Source=brahms;SAS Protocol=2;SAS Port=9888;SAS Machine DNS Name=brahms.unx;User ID=myuserid;Password=xxxxxxxxx;"
Set SASServer.Connection = Connection
If (Not SASServer.StartSAS()) Then
MsgBox "Failed to start the SAS server, terminating export."
Exit Sub
End If
'Get the table to export
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pFeatLayer = pMap.Layer(2)
Set pDisplayTable = pFeatLayer
Set pTable = pDisplayTable.DisplayTable
'Get the feature cursor
Set pFeatSelection = pFeatLayer
Set pSelection = pFeatSelection.SelectionSet
pSelection.Search Nothing, True, pFeatCursor
'Set the export properties
Set SASds.Workspace = SASServer.Workspace
SASds.DSName = "SASUSER.Layer2"
SASds.Append = Append
Set SASds.Table = pTable
If (Not SASds.ExportSelected(SASServer, pFeatCursor, Application)) Then
MsgBox (SASds.ErrorMsg + " Export failed.")
End If
If (Not SASServer.stopSAS()) Then
MsgBox "Unable to terminate the SAS server."
End If
End Sub
|
Export Selected Coordinates
to SAS
Sub ExportSelectedCoordinatesToSAS()
Dim SAScds As SASBridge.CoordDataSet
Dim SASServer As SASBridge.server
Dim Connection As New SASBridge.IOMConnection
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pLayer As ILayer
Dim pFeatLayer As IFeatureLayer
Dim pFeatureSelection As IFeatureSelection
Dim pCursor As ICursor
'Get the vector map layer to export
Set pMxDoc = Application.Document
Set pMap = pMxDoc.FocusMap
Set pLayer = pMap.Layer(3)
Set pFeatLayer = pLayer
'Get the feature cursor
Set pFeatureSelection = pMxDoc.selectedlayer
pFeatureSelection.SelectionSet.Search Nothing, False, pCursor
'Start a local SAS server
Set SAScds = New SASBridge.CoordDataSet
Set SASServer = New SASBridge.server
Connection.ConnString = ""
Set SASServer.Connection = Connection
If (Not SASServer.StartSAS()) Then
MsgBox "Failed to start the SAS server, terminating export."
Exit Sub
End If
'Set the export properties
Set SAScds.Workspace = SASServer.Workspace
SAScds.DSName = "SASUSER.Layer3"
SAScds.Append = False
Set SAScds.FeatLayer = pFeatLayer
'Export the data
If (Not SAScds.ExportSelected(SASServer, pCursor, Application)) Then
MsgBox (SAScds.ErrorMsg + " Export failed.")
End If
If (Not SASServer.stopSAS()) Then
MsgBox ("Unable to terminate the SAS server.")
End If
End Sub
|