Chapter Contents |
Previous |
Next |
SAS ODBC Driver User's Guide and Programmer's Reference |
Internally, the SAS System supports two data types for storing data:
CHAR | fixed-length character data, 200-character maximum |
NUM | double-precision floating-point number |
However, by using SAS format information, the SAS ODBC driver is able to represent other ODBC data types, both when responding to queries and in CREATE TABLE requests. (A SAS format is a string that describes how data should be printed. The SAS System associates format information with each column in a table.)
The following sections explain conventions for data type representation that the SAS ODBC driver follows.
For information about user-specified SQL options that can also affect data type representations, see User-Specified SQL Options. For more information about SAS formats, see SAS Language Reference: Dictionary.
Data Types Reported on Queries |
However, the SAS System stores dates and times as numbers, and the SAS ODBC driver uses SAS format information to infer the following additional SQL data types from NUM data types:(footnote 1)
SAS Data Type | SQL Data Type |
---|---|
NUM FORMAT=DATEn. | SQL_DATE |
NUM FORMAT=TIMEn. | SQL_TIME |
NUM FORMAT=DATETIMEn. | SQL_TIMESTAMP |
In each of the previous FORMAT= strings, n is a number that selects the printable representation by specifying a width for printing. The value of n is not relevant to the driver.
Creating or Comparing Date, Time, and Datetime Values |
Note: ODBC does not support negative time
values or values greater than one day's worth of seconds. The SAS ODBC driver
returns an error for time values that are less than 0 or greater than 86399
(the last second of the day).
Both ODBC and SAS date, time and datetime literals are supported by the SAS ODBC driver.
select * where hiredate = {d'1995-01-02'} or select * where hiredate = '02jan1995'd
Instead, use a datetime literal such as
select * where hiredate = {ts'1995-01-02 00:00:00'} or select * where hiredate = '02jan1995:00:00:00'dt
Interpretation of Data Types in CREATE TABLE Requests |
CREATE TABLE | ODBC Data Type | SAS Data Type |
---|---|---|
Data Type Name | ||
char(w) | SQL_CHAR | CHAR(w) |
num(w, d) | SQL_DOUBLE | NUM |
num(w, d) | SQL_FLOAT | NUM |
integer | SQL_INTEGER | NUM FORMAT=11.0 |
date9x | SQL_DATE | NUM FORMAT=DATE9. |
datetime19x | SQL_TIMESTAMP | NUM FORMAT=DATETIME19. |
time8x | SQL_TIME | NUM FORMAT=TIME8X |
The data type names listed in the first column of the table are the values that are returned by SQLColAttributes (with the parameter SQL_COLUMN_TYPE_NAME) and by SQLGetTypeInfo. For all CREATE TABLE statements, the SAS ODBC driver translates these data type names into the respective SAS data types shown under the SAS Data Type heading. Do not try to use the ODBC data types directly in SAS.
In a CREATE TABLE statement, any FORMAT= specification
is passed on to the SAS System unmodified, so a column within a table (or
data set) can be created according to any exact specification that is required
for its use within SAS. For example, in the following CREATE TABLE statement,
variable
B
's data type and format are passed directly to the
SAS System.
CREATE TABLE SASUSER.TABLE1 (A INTEGER, B NUM FORMAT=9.5, C CHAR(40) );
Chapter Contents |
Previous |
Next |
Top of Page |
Copyright 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.