Reading a SAS Dataset using C#

Reply
Regular Learner
Posts: 1

Reading a SAS Dataset using C#

Hi all,

 

Trying to read a SAS dataset using C#. Found some examples and have been following those. I am getting hung up with the error "The table could not be found or the index file is missing."

 

The dataset I am trying to read is named "c5plcum.sas7bdat"

 

I used and OLE Connection string using LocalProvider and the sas data file as the datasource (connection opens correctly). Then I use a table direct command with the table name as the command text and attempt to execute reader. This is where I get the error. I tried "C5PLCUM" as the table name. I tried it lower case. I opened the data set in SAS and saw the table name was "_EXP0_.C5PLCUM" so I tried that. Also tried "_EXP0_". All gave me the error.

 

Any insights would be greatly appreciated.

 

OleDbConnection conn = new OleDbConnection();

 

string sasLibr = @"c:\data\c5plcum.sas7bdat";

string sasTbl = @"_EXP0_"; //@"_EXP0_.C5PLCUM";

conn.ConnectionString = @"Provider=sas.LocalProvider; Data Source=" + sasLibr;

try

{

     conn.Open();

     tbStatus.Text = @"SAS Server Version: " + conn.ServerVersion;

}

catch (Exception ex)

{

      tbStatus.Text += @"ERROR: " + Environment.NewLine + ex.Message;

      if ((conn != null) && (conn.State != ConnectionState.Closed))

          conn.Close();

      return;

}

 

OleDbCommand cmd = conn.CreateCommand();

cmd.CommandType = CommandType.TableDirect;

cmd.CommandText = sasTbl;

OleDbDataReader rdr;

try

{

     rdr = cmd.ExecuteReader();

}

catch (Exception ex)

{

      tbStatus.Text += @"ERROR: " + Environment.NewLine + ex.Message;

      if ((conn != null) && (conn.State != ConnectionState.Closed))

           conn.Close();

     return;

}

 

SAS Employee
Posts: 18

Re: Reading a SAS Dataset using C#

SAS tables are referenced by libraryname.tablename so try changing your 

string sasLibr = @"c:\data\c5plcum.sas7bdat";

string sasTbl = @"_EXP0_"; //@"_EXP0_.C5PLCUM";

 

string sasLibr = @"c:\data\";

string sasTbl = @"c5plcum";

 

and/or here is a reference site that should help

http://support.sas.com/documentation/tools/oledb/index.htm

 

 

 

Ask a Question
Discussion stats
  • 1 reply
  • 346 views
  • 0 likes
  • 2 in conversation