Help using Base SAS procedures

Export SAS Table to SQL Server: Variable type Error

Accepted Solution Solved
Reply
Contributor
Posts: 34
Accepted Solution

Export SAS Table to SQL Server: Variable type Error

I can successfully export a table to a sql server database using the following code:

 

LIBNAME SQL ODBC DSN="sql server" user=SAS_Connect pw=SASPass1; 

 

proc sql;
    drop table sql.baseball;
proc sql;
    create table sql.baseball as
select *
    from sashelp.baseball
;quit;

 

This works fine for the example data but I am running into issues when I try to export larger tables (280 variables, 80,000 rows). I am receiving this error:

 

ERROR: CLI execute error: [Microsoft][ODBC SQL Server Driver][SQL Server] Arithmetic overflow error for type smallint, value = 33841.000000. : [Microsoft][ODBC SQL Server Driver][SQL Server]The statement has been terminated.

 

I am assuming that this is because when assigning sql server datatypes, the first observation establishes which type the algorithm thinks is best and then an error will occur if subsequent observations do not match that data type e.g. exceed allowable values. Is there a way that I can automatically set all numeric SAS variables to a type of "big int"? I would prefer to not have to specify the data type for all 280 variables. I have seen the "dtype" option for use with SAS/Access but I have only seen it applied to importing data. Please note that I have about zero experience working with sql server. I would simply like to export a large SAS table with many different variables similar to the example above. Any help or advice is much appreciated.

 

Best,

Daniel

 


Accepted Solutions
Solution
‎09-29-2015 03:37 PM
Super User
Posts: 3,106

Re: Export SAS Table to SQL Server: Variable type Error

Here's a link to the default data types that SAS defines:

 

http://support.sas.com/documentation/cdl/en/acreldb/68028/HTML/default/viewer.htm#n0h4i25zq3t58en1lg...

 

I suggest you change the SAS format on the numeric variable giving the problem to having some decimal places (eg 8.2). That should switch the data type to NUMERIC.

View solution in original post


All Replies
Solution
‎09-29-2015 03:37 PM
Super User
Posts: 3,106

Re: Export SAS Table to SQL Server: Variable type Error

Here's a link to the default data types that SAS defines:

 

http://support.sas.com/documentation/cdl/en/acreldb/68028/HTML/default/viewer.htm#n0h4i25zq3t58en1lg...

 

I suggest you change the SAS format on the numeric variable giving the problem to having some decimal places (eg 8.2). That should switch the data type to NUMERIC.

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 1 reply
  • 348 views
  • 0 likes
  • 2 in conversation