SAS Date Formats Incompatible with SQL Server Date

前端 未结 3 1096
清酒与你
清酒与你 2021-01-27 14:13

I\'m fairly new to SAS and recently we migrated some of our SAS datasets to a SQL Server table but we are still using SAS to do our analysis. I have run into a problem when SAS

3条回答
  •  说谎
    说谎 (楼主)
    2021-01-27 14:53

    SQL Server introduced new date and datetime types in SQL Server 2008 (prior, there was only one type for all date/datetime variables). This usage note suggests that you need to install a new set of SQL Server ODBC drivers for SAS to read the date variables correctly. It suggests this would be installed normally if you have SQL Server 2008 Tools (like SQL Server Management Studio) on the machine that is doing the ODBC connection, but you might have multiple drivers installed and need to ensure you are using the right one.

    That said, it is not a bad idea to use pass-through SQL to pull the data across, as that might make it easier to do the pull (as you don't have to worry as much about the ODBC driver). The generalized pass through connection string is

    proc sql;
       connect to odbc (required="driver=sql server native client 10.0;
    Server=server;Trusted_Connection=Yes;DATABASE=database;");
      create table X as select * from connection to odbc(... sql server native code here ...);
    quit;
    

    From your question it sounds like you're more of a SQL person and can then construct the query yourself; if you are not, either edit the question to include that request (and then either a SQL Server person or myself will answer). You can use SAS macro variables in that query (ie, to pass the current date) as long as you do not enclose them or the query in single quotes.

提交回复
热议问题