05-16-2015 03:26 PM
So I am trying to create a table in Teradata from Oracle using SAS.
When I do that, SAS by default remove the trailing spaces, but I want those spaces.
If I have a value as 026... (dot representing spaces here)
SAS load them into a Teradata table as : 026
How can I achieve that?
Thanks in advance.
05-18-2015 02:07 PM
First of all thank you everyone for taking out their valuable time and help me out to solve my problem.
Thanks Tom for giving me an idea to deal it on Oracle level by specifying another column of length.
I am not making that space value column as my UPI in landing, but the UPI in fact in landing is a REC_ID column which is a surrogate key.
UPI for that column has been made in the staging area.
Pardon me if I did something wrong as I am a fresher.
I solved the problem by executing a simple pass through query.
This is how I did it.
Correct me if I am wrong but for now the problem has been solved and if anyone wishes the same to replicate the data from the source to the target as the way it was stored in source then one may follow this:
Trailing spaces in a column at Oracle source end but not coming in target Teradata table.
1. Pass through in Oracle, replace space by '$', insert into Teradata target table.
2. Again pass through in Teradata, Write an update query to replace '$' with spaces.
connect to oracle(......);
insert into tera.tbl1
select * from connection to oracle
, replace(col2,' ','$') as col2
disconnect from oracle;
connect to teradata(.....);
execute( update schema.tbl2
set col2 = oreplace(col2,'$',' ')
disconnect from teradata;
05-17-2015 02:32 AM
Thanks for the quick reply. Not even that working.
I tried first converting spaces into hashes by using TRANWRD and then replacing # by spaces again.
But when I do that, SAS converts all the non occupied places as spaces whether it was in the column value or not.
Approach I'm using is- Tranwrd(column1,"20"x,"#")
for eg, if the column1 has some values and length as 10 $
(Representing dot as spaces)
First it converts like-
But it should be like,
05-17-2015 03:46 AM
How do you load them into a Teradata table ?
If it is SQL , specify its length as
select var length=10 ......... from ....
If it was data step, specify its length as
length var $ 10 ;
05-17-2015 04:01 AM
Change the question as it as about SAS-Teradata not only SAS. TD (Teradata) is a RDBMS having his own datatypes a tri-value-logic with nulls and different date-time formats supporting interval according to SQL:2013 whereas SAS is using SQL:99. That are a lot of differences.
Look at the SAS-TD access translation SAS/ACCESS(R) 9.4 for Relational Databases: Reference, Sixth Edition char and varchar from TD to SAS are the same. Going from SAS to TD the default is only CHAR
Review the TD varchar definition that one is removing trailing blanks when loading loading data. The active hardware compression for blanks at char fields having spaces could be as effective.
Remember TD is a special one. Loading data to TD can have issues, they will not return as errors instead some dedicated tables are created having the erroneous ones.
05-17-2015 04:57 AM
I agree with you, but not only Teradata, even if I am making a data set in SAS, then also the spaces are not coming. Its like SAS is removing trailing spaces by default.
05-17-2015 05:03 AM
No SAS is not removing the spaces, in contrary spaces are always added to fill it up to full fixed storage length. The fixed-storage like the char in TD.
This behavior is the reason why you need to trim (remove trailing spaces) before you can effective concatenate strings. Fixed=fixed there must be something there.
You must have some other issue. Describe it better with preferable some code showing that.
05-17-2015 05:09 AM
I just wrote a small data step.
Col1= 'Anant ';
When I copy paste the value Anant in a notepad, there is no trailing space.
also the length has given me 5 as output.
But it should be 10 (as I've given 5 spaces), right?
05-17-2015 05:49 AM
Yes that is OK, but I don't only want to find the length.
my main concern is to read these two as different values.
If you write,
select distinct col1 from x;
Then the output will be-
But these are two different values.
Need further help from the community? Please ask a new question.