10-29-2014 12:40 PM
I have a problem in my sql sas procedures; I do a join between two tables to retrieve a field with a "case When "
CASE WHEN A.SOUR in ('BIO') then G.FACT else F.FACT end as FACT
the problem is that the attributes of the two fields are different in the two tables (G and F); I have a number and a varchar; This column will automatically take a varchar format and I want it to be number because later in my sql procedures I will join this field with the same but with a number format on other tables.
I tried an update on the table but I get an error: Bad character in size
If someone has an idea ..
Thank you in advance
10-29-2014 01:06 PM
You have to convert the char variable to number.
If G.FACT is varchar then use: CASE WHEN A.SOUR in ('BIO') then input(G.FACT,best12.) else F.FACT end as FACT
or If F.FACT is varchar then use: CASE WHEN A.SOUR in ('BIO') then G.FACT else input(F.FACT,best12.) end as FACT
I used best12. as the informat in the example but you should use the correct one.
10-30-2014 04:37 AM
thanks but i tried this and i get an error : "
Syntax error: expected something between the 'then' keyword and the 'input'
I have another question please ; which format should i apply if the column is an integer in teradata ?
10-30-2014 07:15 AM
There is no varchar in SAS. SAS only knows character (fixed length) and numeric.
format x y 12. z $12.;
input x y z;
1 3 3
2 3 5
create table want as
when x = 1
end as newvar
Could you post log of the SQL that ended with the syntax error?
10-30-2014 09:15 AM
thanks Kurt ! what do you mean by log ?
I'm working with many tables in teradata using proc sql everytime ; so I don't use "data" syntax .
When i tried : CASE WHEN A.SOUR in ('BIO') then input(G.FACT,best12.) else F.FACT end as FACT , i get this error :
ERROR: Teradata execute: Syntax error: expected something between the 'then' keyword and the 'input'
G.FACT is a varchar 50 in teradata and F.FACT is an integer and I want G.FACT as an integer in my proc sql in SAS
I expect that it's more clear
10-30-2014 09:23 AM
Every time you run SAS code, you get a log either in the log window (base SAS) or in a log tab (Enterprise Guide).
But see here:
ERROR: Teradata execute
You do not have a SAS problem, you have a Teradata problem. I suspect that Teradata has a different syntax concerning the input keyword, and this part of the SQL is actually handled at the Teradata side.