We have the following requirement where user is having only OLE DB and SAS universal viewer. Could you please confirm, shall we Read/Write SAS dataset using C# with local SAS universal viewer and OLEDB connection.
Requirement:
To achieve this, we are doing the following have to do the following steps in visual studio with following references. However we are getting the issue while creating a local workspace which highlighted in yellow colour.
WorkspaceManager sasWM = new SASWorkspaceManager.WorkspaceManager();
sasWS = (SAS.Workspace)sasWM.Workspaces.CreateWorkspaceByServer("LocalWS", Visibility.VisibilityProcess, null, "", "", out xmlInfo);
Code for above steps:
SAS.Workspace sasWS;
string xmlInfo;
WorkspaceManager sasWM = new SASWorkspaceManager.WorkspaceManager();
sasWS = (SAS.Workspace)sasWM.Workspaces.CreateWorkspaceByServer("LocalWS", Visibility.VisibilityProcess, null, "", "", out xmlInfo); //Here i am getting the error
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=sas.IOMProvider; SAS Workspace ID=" + sasWS.UniqueIdentifier;
// Set SAS dataset library path (libname)
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"libname MyLib 'c:\temp\IOM'";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
// Retrieve SAS data into a DataSet
string sql = "select * from MyLib.DV";
OleDbDataAdapter da = new OleDbDataAdapter(sql, conn);
System.Data.DataSet ds = new System.Data.DataSet("SAS");
da.Fill(ds);
//WriteDataSet(ds.Tables[0]);
Error Details:
An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in SASReader.exe
Additional information: <connectionAttempts>
<connectionAttempt>
<sasserver></sasserver>
<sasmachinednsname></sasmachinednsname>
<sasport>0</sasport>
<saslogin></saslogin>
<status>0x80040154</status>
<description>Class not registered
</description>
</connectionAttempt>
</connectionAttempts>
As I understand it, this isn't going to work. As the name suggests the SAS Universal Viewer is just for viewing existing SAS datasets. You can't use it to translate from or to other data types / sources:
http://support.sas.com/documentation/onlinedoc/univiewer/
You need to have a working version of SAS installed to do what you want - to read a SAS dataset and load it into a DBMS table or vice versa. The only other option I can think of would be a third-party tool that can translate SAS datasets
To create a local Workspace, you need a local version of SAS installed. And method is something like this:
SAS.Workspace _workspace = null;
// Connect using COM protocol, locally installed SAS only SASObjectManager.IObjectFactory2 obObjectFactory = new SASObjectManager.ObjectFactoryMulti2(); SASObjectManager.ServerDef obServer = new SASObjectManager.ServerDef(); obServer.MachineDNSName = "localhost"; obServer.Protocol = SASObjectManager.Protocols.ProtocolCom; obServer.Port = 0; _workspace = (SAS.Workspace)obObjectFactory.CreateObjectByServer(Name, true, obServer, null, null);
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.