Thanks Chris. I ultimately did something very similar. I will be pushing the whole solution to github at https://github.com/savian-net/ExportFromSasDataset
Here is the pertinent snippet for posterity:
/// <summary>
/// Gets a SAS dataset from the specified location but using the SAS formats for the results. Only supported
/// Base SAS formats will be handled. If a user-defined format is encountered, the method will fail.
/// </summary>
/// <param name="sasLibrary">The physical location of the SAS library to read in the data </param>
/// <param name="sasDataSet">The name of the SAS dataset to read</param>
/// <returns>.NET datatable. All values returned will be strings.</returns>
public static DataTable GetDataSet(string sasLibrary, string sasDataSet)
{
DataTable dt = new DataTable();
try
{
ADODB.Recordset set = new ADODB.Recordset();
ADODB.Connection conn = new ADODB.Connection();
conn.Provider = "sas.LocalProvider.1";
conn.Properties["Data Source"].Value = sasLibrary;
conn.Open();
set.ActiveConnection = conn;
var connProps = conn.Properties.OfType<ADODB.Property>().Select(p => new { p.Name, p.Value }).ToList();
var recordSetProps = set.Properties.OfType<ADODB.Property>().Select(p => new { p.Name, p.Value }).ToList();
if (_options.Formatted)
{
set.Properties["SAS Formats"].Value = "_ALL_";
}
set.Open(sasDataSet, Missing.Value, ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly, (int)ADODB.CommandTypeEnum.adCmdTableDirect);
OleDbDataAdapter da = new OleDbDataAdapter();
da.Fill(dt, set);
dt.TableName = sasDataSet.ToUpper();
conn.Close();
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
... View more