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()
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.