Here are the data types that SAS/ACCESS Interface to Teradata supports:
| BYTE(n) |
| VARBYTE(n) |
| CHAR (n) |
| VARCHAR (n) |
| LONG VARCHAR |
| DATE |
| TIME(n) |
| TIMESTAMP (n) |
Date type columns might contain Teradata values that are out of range for SAS, which handles dates from A.D. 1582 through A.D. 20,000. If SAS/ACCESS encounters an unsupported date (for example, a date earlier than A.D. 1582), it returns an error message and displays the date as a missing value.
| BYTEINT | INTEGER |
| DECIMAL(n,m) | NUMBER |
| FLOAT | REAL | DOUBLE PRECISION | SMALLINT |
For details about these data types, see your Teradata documentation.
Teradata has a special value that is called NULL. A Teradata NULL value means an absence of information and is analogous to a SAS missing value. When SAS/ACCESS reads a Teradata NULL value, it interprets it as a SAS missing value.
By default, Teradata columns accept NULL values. However, you can specify columns so that they do not contain NULL values. For example, when you create a SALES table, specify the CUSTOMER column as NOT NULL. This tells Teradata not to add a row to the table unless the CUSTOMER column for the row has a value. When creating a Teradata table with SAS/ACCESS, you can use the DBNULL= data set option to indicate whether NULL is a valid value for specified columns.
For more information about how SAS handles NULL values, see Potential Result Set Differences When Processing Null Data.
To control how SAS missing character values are handled, use the NULLCHAR= and NULLCHARVAL= data set options.
This table shows the default formats that SAS/ACCESS Interface to Teradata assigns to SAS variables when using the LIBNAME statement to read from a Teradata table. SAS/ACCESS does not use Teradata table column attributes when it assigns defaults.
|
Teradata Data Type |
Default SAS Format |
|---|---|
|
CHAR(n ) |
$n (n<= 32,767) |
|
CHAR(n ) |
$32767.(n>32,767) 1 |
|
VARCHAR(n ) |
$n (n<= 32,767) |
|
VARCHAR(n ) |
$32767.(n> 32,767) 1
|
|
LONG VARCHAR(n ) |
$32767. 1 |
|
BYTE(n ) |
$HEXn. (n<= 32,767) |
|
BYTE(n )1 |
$HEX32767.(n> 32,767) |
|
VARBYTE(n ) |
$HEXn. (n<= 32,767) |
|
VARBYTE(n ) |
$HEX32767.(n> 32,767) |
|
INTEGER |
11.0 |
|
SMALLINT |
6.0 |
|
BYTEINT |
4.0 |
|
DECIMAL(n, m )2 |
(n+2 ).(m ) |
|
FLOAT |
none |
|
NUMBER2 |
w.d |
|
DATE3 |
DATE9. |
|
TIME(n)4 |
for n=0, TIME8. for n>0, TIME9+n.n |
|
TIMESTAMP(n)4 |
for n=0, DATETIME19. for n>0, DATETIME20+n.n |
|
TRIM(LEADING FROM c) |
LEFT(c) |
|
CHARACTER_LENGTH(TRIM(TRAILING FROM c) |
LENGTH(c) |
|
(v MOD d) |
MOD(v,d) |
|
TRIMN(c) |
TRIM(TRAILING FROM c) |
| 1 When reading Teradata data into SAS, DBMS columns that exceed 32,767 bytes are truncated. The maximum size for a SAS character column is 32,767 bytes. | |
| 2 If the DECIMAL or NUMBER number is extremely large, SAS can lose precision. For details, see Supported Teradata Data Types. | |
| 3 To learn how SAS/ACCESS handles dates that are outside the valid SAS date range, see Supported Teradata Data Types. | |
| 4 TIME and TIMESTAMP are supported for Teradata Version 2, Release 3, and later. The TIME with TIMEZONE, TIMESTAMP with TIMEZONE, and INTERVAL types are presented as SAS character strings and are therefore harder to use. | |
When you create Teradata tables, the default Teradata columns that SAS/ACCESS creates are based on the type and format of the SAS column. The following table shows the default Teradata data types that SAS/ACCESS assigns to the SAS formats during output processing when you use the LIBNAME statement.
|
SAS Data Type |
SAS Format |
Teradata Data Type |
|---|---|---|
|
Character |
$w. $CHARw. $VARYINGw. |
CHAR[w] |
|
Character |
$HEXw. |
BYTE[w] |
|
Numeric |
A date format |
DATE |
|
Numeric |
TIMEw.d |
TIME(d) |
|
Numeric |
DATETIMEw.d |
TIMESTAMP(d) |
|
Numeric |
w.(w≤2) |
BYTEINT |
|
Numeric |
w.(3≤w≤4) |
SMALLINT |
|
Numeric |
w.(5≤w≤9) |
INTEGER |
|
Numeric |
w.(≤10w≤18) |
DECIMAL |
|
Numeric |
w.(w≥19) |
NUMBER |
|
Numeric |
w.d |
DECIMAL(w-1,d) |
|
Numeric |
all other numeric formats |
FLOAT |
To override any default output type, use the DBTYPE= data set option.
When NUMBER data is read into SAS, SAS/ACCESS automatically converts this data to FLOAT values. Therefore, when you use NUMBER data in a DATA step or in procedures, that data is automatically available for calculations in SAS.
Be aware that when performing calculations on numeric values and when storing numeric values, SAS maintains up to 15 digits of precision. When you read values that contain more than 15 decimal digits of precision from a database into SAS, the values that are read are rounded to meet this condition. For noncomputational purposes, such as storing ID values or credit card numbers, you can read the data in as character data. For more information, see Your Options When Choosing Your Needed Degree of Precision.
The only time when you need to convert NUMBER data to another data type is when you pass native SQL queries to the Teradata database. For more information, see the next section.
When you interact with NUMBER data in native Teradata SQL code that you pass to the database, change the NUMBER data to FLOAT values for use in SAS. To do this, use the Teradata CAST function. This ensures that the data is usable by SAS. Similarly, you can use the CAST function in native Teradata SQL to change from a FLOAT value to a NUMBER value when you write to Teradata.
proc sql;
connect to teradata(user=myuser pass=myPwd
server=myServer);
select * from connection to Teradata(select col1, cast(col2 as FLOAT), col3
from TDlib.table);
... additional code ...
quit;
The FEDSQL and DS2 procedures provide native support for the Teradata NUMBER data type. That is, when you create a Teradata table and define a column of type NUMERIC(p,s) in a FedSQL or DS2 program, SAS creates a column as NUMBER(p,s) in Teradata. There is no need for any conversions to or from the FLOAT data type. For more information about how FedSQL and DS2 data types are mapped to Teradata data types, see Data Types for Teradata in SAS DS2 Language Reference or Data Types for Teradata in SAS DS2 Language Reference.
proc fedsql;
create table tera.test(col1 numeric(4,2));
insert into tera.test values(12.34);
select * from tera.test;
quit;
proc ds2;
data test;
dcl numeric col1(4,2);
method=run();
Col1=12.34; output;
end;
endData;
run;
quit;