In this recipe, you learn how to prepare the local, SAS/SHARE, and IOM data providers to access SAS formatting features. Sample code for the ADO recipe is included.
Applies to: | SAS Local Data Provider, SAS/SHARE Data Provider, SAS IOM Data Provider |
Implement using: | ADO or OLE DB |
SAS implements a set of formats that can be used to transform basic character and numeric values into formatted character values. In ADO, formats are controlled with the "SAS Formats" customized recordset property. This property takes a string value that specifies the format you want to use, and specifies any optional overriding information. The string value also lists one or more columns to which the format should be applied. Use the following form to enter the string value:
[+]COLUMN[=FORMAT[w].[d]]
Following is an explanation of the form:
The order in which the columns are listed in the string does not affect the order in which they are returned by an ADO Recordset object.
For example, assume that a data set has three variables that appear in the following order:
The following string value is based on the sample data set:
SALEDATE=MMDDYY8.,+PRICE=DOLLAR8.2
The results appear in the following four columns on the ADO Recordset object:
Note: The fourth column was constructed through the use of the + modifier; it is not persisted beyond the life of its exposure on the ADO Recordset object.
In the absence of explicit format information, or if you specify "_ALL_" as the "SAS Formats" property, the SAS providers apply format properties to all columns according to the following rules:
To see the same physical column of data exposed as two columns, one formatted and one unformatted, prefix the column name with the plus (+) sign modifier. When you make this request, the formatted column appears as a constructed, temporary column named COLUMN_FORMAT. The formatted column is not persisted beyond the life of its exposure on the ADO Recordset object.
To see all columns returned in both their formatted and unformatted forms, use the form "+_ALL_".
Note: Data integrity problems can occur when the data provider cannot determine which version of a column (formatted or unformatted) should be written to the data set. To prevent these problems, use the + modifier to restrict the recordset to read-only access.To determine a table's column metadata at run time, use the Connection object's OpenSchema method and set its query type parameter to adSchemaColumns. The returned recordset will contain the persisted SAS format information for each column, along with the defined OLE DB schema information.
The following sample code shows how to set the "SAS Formats" property so that the columns in the recordset will include the formatting as indicated by the "SAS Formats" value.
Dim cnt As ADODB.Connection Dim rst As ADODB.Recordset Set cnt = New ADODB.Connection Set rst = New ADODB.Recordset cnt.Open "Provider=sas.LocalProvider.1" cnt.Data Source = "c:\sales" rst.ActiveConnection = cnt rst.Properties("SAS Formats") = "saledate=mmddyy8.,+price=dollar8.2." rst.Open "sales", , adOpenStatic, adLockReadOnly, adCmdTableDirect
Note: The second parameter on the Open method must remain empty, as shown in the code fragment.
An application that calls a SAS provider directly through the OLE DB interfaces should use the SASFORMAT structure with the DBBINDING extensions. For information about how to perform this task, see About Format and Informat Processing with OLE DB.