You can
use the IOM DataService class to assign a libref. The following Visual
Basic code shows how this task is done.
Note: To use the
sample code, you must reference these libraries in your Visual Basic
project: SAS Integrated Object Model (IOM) Type Library and the SASObjectManager
Type Library. These libraries are installed with SAS Integration Technologies.
Dim obObjectFactory As New SASObjectManager.ObjectFactory
Dim obConnection As New ADODB.Connection
Dim obRecordset As New ADODB.Recordset
Dim obSAS As SAS.Workspace
Dim obLibRef As SAS.Libref
' Use the SAS Object Manager to establish a SAS workspace object.
set obSAS = obObjectFactory.CreateObjectByServer("MyServer", True, Nothing, "", "")
Dim obObjectKeeper As New SASObjectManager.ObjectKeeper
obObjectKeeper.AddObject(1, "MyServer", obSAS)
' Call the AssignLibref method in order to assign a libref.
Set obLibRef = obSAS.DataService.AssignLibref("mylib", "", "c:\census\data", "")
' Open a connection.
obConnection.Open "Provider=sas.IOMProvider;SAS Workspace ID=" & obSAS.UniqueIdentifier
' Open a data set in the assigned library.
obRecordset.Open "mylib.cities", obConnection, adOpenStatic, adLockReadOnly, adCmdTableDirect
In the
sample code,
obSAS
,
obLibRef
, and
obObjectFactory
are all IOM objects.
For more information about the SAS object hierarchy, see the
SAS Integration Technologies: Windows Client Developer's Guide.