Importing SAS Data into Excel Using ADO Connections

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 8
Accepted Solution

Importing SAS Data into Excel Using ADO Connections

I would like to import data from SAS into excel using ADO and VBA within excel. Does anyone know if it is required that SAS be installed on the client accessing the SAS data or if the SAS Excel plug-in needs to be present?


Accepted Solutions
Solution
‎02-09-2015 04:45 PM
Trusted Advisor
Posts: 1,300

Re: Importing SAS Data into Excel Using ADO Connections

To connect to a remote SAS server you need to install the SAS Integration Technologies client.  This will enable you to use com objects to connect to the remote workspace server and collect data using ADO.

View solution in original post


All Replies
Super User
Posts: 3,108

Re: Importing SAS Data into Excel Using ADO Connections

The SAS ADO Excel plug-in needs to be installed on the PC where Excel is being used.

ADO needs to connect with either a local SAS server, in which case SAS needs to be installed on the PC, or to a remote SAS server, in which case SAS does not need to be installed on the PC.

Occasional Contributor
Posts: 8

Re: Importing SAS Data into Excel Using ADO Connections

I would like to connect to a remote SAS server. If I understand correctly, I will still need the SAS ADO plug-in but will not need SAS installed on my PC?

Thanks for the quick response!

Solution
‎02-09-2015 04:45 PM
Trusted Advisor
Posts: 1,300

Re: Importing SAS Data into Excel Using ADO Connections

To connect to a remote SAS server you need to install the SAS Integration Technologies client.  This will enable you to use com objects to connect to the remote workspace server and collect data using ADO.

Occasional Contributor
Posts: 8

Re: Importing SAS Data into Excel Using ADO Connections

Thanks, accomplished what I wanted to. Appreciate it!

Trusted Advisor
Posts: 1,300

Re: Importing SAS Data into Excel Using ADO Connections

In case it will be helpful to others in the future, here is an example of using ADO to assign a new libref and select from a table within the reference using Powershell.

SasAdoDbExample.ps1

or PHP

SasAdoDbExample.php

$conn = New-Object -ComObject ADODB.Connection

#Connect to a remote server using IOM

$conn.Open('Provider=sas.IOMProvider.9.3;User ID=user;Password=pass;Data Source="";SAS Machine DNS Name=workspace.mycompany.com;SAS Port=8591;SAS Protocol=2')

#Assign a new libref using ADODB

$cmd = New-Object -ComObject ADODB.Command

$cmd.ActiveConnection = $conn

$cmd.CommandType = adCmdText

$cmd.CommandText = 'libname foo "/path/to/something"'

$cmd.Execute()

#SQL data

$recordSet = $conn.Execute("select * from foo.something")

#Collect the data from recordSet into rows array

$recordSet.MoveFirst()

$rows = @()

do

{

   $row = New-Object psobject

   for ($i=0; $i -lt $recordSet.Fields.Count; $i++)

  {

   $row | Add-Member noteproperty `

   -name $recordSet.Fields.Item($i).Name `

   -value $recordSet.Fields.Item($i).Value;

  }

   #yield

   $rows += $row

   $recordSet.MoveNext()

}

until ($recordSet.EOF -eq $true)

#create gridview of data executed in recordSet

$rows | Out-GridView

$recordSet.Close()

$conn.Close()

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 5 replies
  • 688 views
  • 3 likes
  • 3 in conversation