I was working with a SAS proc sql query and uncovered something odd. First, I tried this simple query:
proc sql;
CREATE TABLE test AS
(SELECT
YEAR(dt) AS yr,
MONTH(dt) AS mo,
SUM(val) AS total
FROM
mydb1234.myTable
WHERE
myDate BETWEEN x AND y
GROUP BY
yr, mo);
run;
When I run this query, I receive this error:
ERROR: Teradata row not delivered (trget): Numeric overflow occurred during computation.
From what I can tell, this happens when my summed value gets too large to fit in the data type that proc sql
is trying to use.
I decided that I would just divide the number I am summing:
SUM(val/1000) AS total
However, this had unintended consequences. The summed total was less than a manual sum I did in Excel. The total gets lower as I add more orders of magnitude to the divisor. I'm guessing this is eliminating smaller values that it tries to sum (ex. 10/1000 vs 108/10000, etc) that never reach the sum and are instead read as zeros.
Is there a way to force this proc sql to create a table using a field length that can accomodate my total values? They are in the billion-hundred billion range, so it's nothing that unusual I would think. I was curious to see what you guys thought.