The following
Visual Basic code shows you how to read a SAS data set named
books
that uses formats that are contained in a catalog
named
formats
. The data set is located
in a directory named
c:\storage
. The
catalog is located in a directory named
c:\public
.
Note: If you define
the libref to point to the location where the catalog is stored,
your SAS Workspace Server can access your user-written formats when
you process data sets by using either ADO recordsets or OLE DB rowsets.
' obConnection is an open Connection object.
Dim obRecordset As New ADODB.Recordset
' Use the formats persisted on the data set
obRecordset.Properties("SAS Formats") = "_ALL_"
' Assign a libref for the formats catalog.
obConnection.Execute ("libname library 'c:\public' ")
' Assign a libref for the data set.
obConnection.Execute ("libname mylib 'c:\storage' ")
' The second parameter on the Open method must remain empty.
bRecordset.Open "mylib.books", , adOpenDynamic, adLockReadOnly, adCmdTableDirect
Note: Currently,
user-written formats cannot be processed on the client side, which
is why the IOM provider can process user-written formats but the local,
SAS/SHARE, and Base SAS providers cannot. The IOM provider delegates
all format processing to the server side. However, the local,
SAS/SHARE,
and Base SAS providers do all format processing on the client side.
CAUTION:
Do not attempt to open an ADO Recordset object if the
underlying data set contains user-written formats that are not immediately
available to the IOM workspace.
This action results
in a fatal error that is generated even if you are not attempting
to use the formats when reading the data.