SAS Bridge to ESRI  

Use SAS Bridge for ESRI Objects in a Custom Application

SAS Bridge for ESRI  

The following sample macros export ESRI data to a SAS data set. You can paste the following samples into the Visual Basic Editor in ArcMap.

Simplified VBA code:

Sub ExportToSAS()
  Dim SASds As New SASBridge.CDataSet                     'Data set object
  Dim SASserver As New SASBridge.CServer                  'Server object
  Dim SASwsm As New SASWorkspaceManager.WorkspaceManager  'SAS Workspace Manager
  Dim SASws As SAS.Workspace                              'SAS Workspace
  Dim strConnect As String                                'Connection string
  Dim ExportType As SASBridge.ExportType                  'Export type enum
  Dim Verbose As Boolean
  Dim pMxDoc As esriCore.IMxDocument
  
  Set pMxDoc = ThisDocument
  ExportType = all
  Verbose = True
  
  'Define the output SAS data set
  SASds.DSName = "SASUSER.Export_Output"
  
  'Start the SAS server with null connect string.  This will start a
  ' local sas server.
  If (Not SASserver.StartSAS(strConnect)) Then
    MsgBox "Failed to start the SAS server, terminating export."
    GoTo errHandler
    Exit Sub
  End If
  
  'Use the Create method of the data set object to export the data in one step
  'If (Not SASds.Create(SASserver.Workspace, pMxDoc, ExportType, Verbose)) Then
  '  MsgBox "Export failed."
  '  GoTo errHandler
  'End If
  
errHandler:
  If (Not SASserver.stopSAS()) Then
    MsgBox "Unable to terminate the SAS server."
  End If
End Sub
More advanced VBA code

The following sample gives you a greater degree of flexibility and customization.

Sub ExportToSAS()
  Dim SASds As New SASBridge.CDataSet                      'Data set object
  Dim SASserver As New SASBridge.CServer                   'Server object
  Dim SASwsm As New SASWorkspaceManager.WorkspaceManager   'SAS Workspace Manager
  Dim SASws As SAS.Workspace                               'SAS Workspace
  Dim strConnect As String                                 'Connection string
  Dim ExportType As SASBridge.ExportType                   'Export type enum
  Dim Verbose As Boolean
  Dim pMxDoc As esriCore.IMxDocument
  
  Set pMxDoc = ThisDocument
  ExportType = all
  Verbose = True
  
  'Define the output SAS data set
  SASds.DSName = "SASUSER.Export_Output"
  
  'Start the SAS server with null connect string.  This will start a
  ' local sas server.
  If (Not SASserver.StartSAS(strConnect)) Then
    MsgBox "Failed to start the SAS server, terminating export."
    GoTo errHandler
    Exit Sub
  End If
  
  'Get the table for the layer
  If (Not SASds.LayerTable(pMxDoc)) Then
    MsgBox "Could not get the table pointer."
    GoTo errHandler
  End If
 
  'Get the fields in the table
  If (Not SASds.LayerFields()) Then
    MsgBox "Could not get the table fields."
    GoTo errHandler
  End If

  'Add the fields to the SAS data set
  If (Not SASds.Fields()) Then
    MsgBox "Could not add fields."
    GoTo errHandler
  End If
   
  'Add the rows to the SAS data set
  If (Not SASds.Rows(pMxDoc, SASserver.Workspace, ExportType, Verbose)) Then
    MsgBox "Could not add rows."
    GoTo errHandler
  End If
  
errHandler:
  If (Not SASserver.stopSAS()) Then
    MsgBox "Unable to terminate the SAS server."
  End If
End Sub