Whenever
an informat is applied to a column, the SAS providers also apply format
properties to that column. If a format is not explicitly specified
through the use of the "SAS Formats" property, then the provider that
is being used in the application applies the column's default format.
(For more information about using formats, see Using SAS Formats When You Read Data .)
The following
Visual Basic code uses a simple SAS data set named
people
that contains two columns:
name
and
birthday
.
The code specifies an informat for the
birthday
column, which is sufficient for the task of adding a few new records
to the data set.
' obConnection is an open Connection object.
Dim obRecordset As New ADODB.Recordset
obRecordset.ActiveConnection = obConnection
obRecordset.Properties("SAS Informats") = "birthday=MMDDYY8."
' The second parameter on the Open method must remain empty.
obRecordset.Open "people", , adOpenStatic, adLockPessimistic, adCmdTableDirect
obRecordset.AddNew Array("name", "birthday"), Array("Beth", "02/13/73")
obRecordset.AddNew Array("name", "birthday"), Array("David", "05/01/65")
obRecordset.Close
Because
the "SAS Formats" property is not used to explicitly specify a format
for
birthday
, the column's default
format is used. Because this code only writes data, the applied format
does not affect the results. For applications that read and write
records, you must ensure that each column uses the appropriate informat
and format.
In the
following Visual Basic code, the first statement applies a format
to the
birthday
column. The second
statement applies a complementary informat to the
birthday
column.
obRecordset.Properties("SAS Formats") = "birthday=MMDDYY8."
obRecordset.Properties("SAS Informats") = "birthday=MMDDYY8."
By contrast,
in the following code, the property settings for
birthday
are not complementary. The format (DOLLAR9.2) implies that the underlying
numeric value is monetary, but the informat (MMDDYY8.) implies that
the underlying value is a SAS date.
obRecordset.Properties("SAS Formats") = "birthday=DOLLAR9.2"
obRecordset.Properties("SAS Informats") = "birthday=MMDDYY8."
Even though
this pairing of format and informat is not logical, the providers
will not prohibit you from entering this type of configuration.
You must make reasonable choices.
Note: As with informats,
you can use the "_ALL_" keyword to specify that all columns use either
system default formats or persisted formats.