0

I'm currently trying to automate through SAS DI a piece of code that I've written in SAS EG.

While it runs without any issue in SAS EG, DI is returning an error on a SQL statement that is executed on my Teradata server.

the error is the following:

Syntax error, expecting one of the following: !, !!, &, (, ), *, **, +, ',', -,

'.', /, , =, , =, >, >=, ?, AND, BETWEEN, CONTAINS, EQ, EQT, GE, GET, GT, GTT,

 IN, IS, LE, LET, LIKE, LT, LTT, NE, NET, NOT, NOTIN, OR, ^, ^=, |, ||, ~, ~=. 

and this is the line that Is causing the error:

SELECT CAST(EV_ID as VARCHAR(20)) AS EV_ID.

This cast statement is necessary as EV_ID is a BIGINT and SAS wouldn't be able create a table with this field otherwise.

The full code is the following:

proc sql;
    connect to teradata (user=&tera_usr pass="&tera_pw" server=tdprod);
    CREATE TABLE OVERALL_SAMPLE_TF AS SELECT * FROM connection to teradata(
SELECT  A.EV_ID, A.CreatedDate, A.CompletionDate, A.SortCode,
    A.SenderBIC, A.ReceiverBIC, A.NumberOfHitsPerAlert,
    A.Level1ExecutionUser, A.Level2ExecutionUser, A.Final_Level,
    A.Currency, A.Iban, A.Account_Number, A.T_Transaction, A.Last_Operator,
    A.MessageID, A.Message_Type, A.Nature, A.Decision_Type, A.Branch_Contact,
    A.Other_Bank_Contact, A.CompletionDate_TIMESTAMP,
    A.Amount,
    B.Franchise, B.Sub_Franchise, B.Sub_Sub_Franchise
FROM
(SELECT X.*,Y.DIV_ID
        FROM
            ( SELECT CAST(EV_ID as VARCHAR(20)) AS EV_ID,
                CreatedDate, CompletionDate, SortCode,
                SenderBIC, ReceiverBIC, NumberOfHitsPerAlert,
                Nonblocking, Level1ExecutionUser, Level2ExecutionUser, Final_Level,
                Currency, Iban, Account_Number, T_Transaction, Last_Operator,
                MessageID, Message_Type, Nature, Decision_Type, Branch_Contact,
                Other_Bank_Contact, CompletionDate_TIMESTAMP,
                Amount 
            FROM BAC_AML.EVENT_STATUS_ALERT_TF WHERE
                CompletionDate >= ADD_MONTHS(current_date - EXTRACT(DAY FROM current_date)+1, -1)
                AND CompletionDate <= (current_date - extract(day from current_date)+1)-1
                AND CompletionDate NE '99991231' (date, format 'yyyymmdd')
                AND Final_Level>0
                AND UPPER(DECISION_TYPE) IN ('PASS', 'PASS_L1', 'FAIL', 'UNQUEUE', 'RECHECKED')
                QUALIFY ROW_NUMBER() OVER (PARTITION BY EV_ID 
                ORDER BY CompletionDate_TIMESTAMP DESC) = 1 
            ) AS X
            LEFT JOIN
            (SELECT CAST(EV_ID as VARCHAR(20)) AS EV_ID, CAST(DIV_ID as VARCHAR(20)) AS DIV_ID 
             FROM BAC_AML.TF_FRANCHISE 
            ) AS Y
            ON X.EV_ID=Y.EV_ID
 ) AS A
 LEFT JOIN
(SELECT CAST(FR_KEY as VARCHAR(20)) AS FR_KEY,
        L1_Empos_Name, L2_Emp_Posn_Name, L3_Emp_Posn_Name,
        L4_Emp_Posn_Name, Franchise, Sub_Franchise, Sub_Sub_Franchise,
        ORG_MODEL_LINK 
 FROM BAC_AML.FRANCHISE_LOOKUP
 WHERE UPPER(FRANCHISE) IN ('PBB','CPB','ULSTER','NWM')
 ) AS B
 ON B.FR_KEY=A.DIV_ID;

);
disconnect from teradata;
quit;

Please would you be able to help?

thank you.

Joe
  • 62,789
  • 6
  • 49
  • 67
  • 1
    Just to make sure this in't a typo, in your error you list `AS EV_ID.` not `AS EV_ID,` - which is in your actual code? – Joe May 10 '18 at 15:38
  • And - how are the macro variables defined in DI. Are they prompts? I would say that it's a bit odd to have the connection built in the query like this in DI, usually you'd handle it outside through a libname (in the metadata) and then use `CONNECT USING`. – Joe May 10 '18 at 15:55

1 Answers1

0

Remove the double quotes from "&tera_pw", SAS notes here.

Correct line shoule be like this:

connect to teradata (user=&tera_usr pass=&tera_pw server=tdprod);
momo1644
  • 1,769
  • 9
  • 25
  • 2
    I don't believe the quotes are a problem - I've always understood that they're optional (they can be included or not, and will work either way). – Joe May 10 '18 at 15:13
  • Unfortunately I don't access to Teradata in environment to validate your comment. I think it may depend on if you connect via ODBC or ACCESS interface. My answer is based on the SAS note http://support.sas.com/kb/41/629.html – momo1644 May 10 '18 at 15:32
  • I read the note, and similarly can't directly access Teradata; but I don't see anything in the note that says anything about quotes one way or the other, and it's very common in SAS notes like this to not be thorough. I'm also not sure that would cause the kind of error OP is seeing, though honestly I'm surprised to see it at all in a passthrough query so who knows. – Joe May 10 '18 at 15:35
  • I copied the code to my EG 5.1 and it doesn't highlight any syntax error. I am also surprised. – momo1644 May 10 '18 at 15:39