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?
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.
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.
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!
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.
Thanks, accomplished what I wanted to. Appreciate it!
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.
or 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()
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.