Date: Sat, 4 Sep 2010 09:27:46 -0400
Reply-To: Suzanne McCoy <Suzanne.McCoy@CATALINAMARKETING.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: Suzanne McCoy <Suzanne.McCoy@CATALINAMARKETING.COM>
Subject: Re: SQL server dates not date times
Content-Type: text/plain; charset="us-ascii"
New school comment:
Definitely look at oledb instead. I found it much faster against SQL/Server 2008 using 9.1.3 in a Windows Server environment. With OLEdb you can also use ssid= to allow the users to authenticate against AD instead of the database so you don't have to put username and password on the connection string.
Old school idea:
Years ago, back in version 6, we were using Oracle 5.something and upgraded to 5.3 (?). Oracle did something to the way they stored datetimes. It was still number of seconds since a point in time but the point in time was so far back that SAS didn't recognize it. We ended up building views adding ~32K to the value and it resolved the issue so we read from views instead of tables. SQL/Server 2008 may store the dates a bit differently than the datetimes. If you could dump unformatted values of both data types there may be a difference in the number of siqnificant digits that you could use to tell which type was which.
From: SAS(r) Discussion [SAS-L@LISTSERV.UGA.EDU] On Behalf Of Quentin McMullen [qmcmull@YAHOO.COM]
Sent: Friday, September 03, 2010 5:39 PM
Subject: Re: SQL server dates not date times
Thanks Boss (and thanks to Mike as well- oh how I miss the halls of SAS
Somehow I managed to write the whole post below without mentioning that we
are using odbc. But despite that oversite, Sig I think your diagnosis is
correct. I am going to look into this some more next week. But my sense
is the ODBC middleware is telling SAS the wrong variable attribute.
I will look into an OLE solution at the same time, as if these options
prove useful we could consider using that instead of ODBC.
Of course when I was writing this morning, was hoping someone would
say "Of course you can store a date column in SQL server and have SAS pull
it down and know it's a date." But as that hasn't happened yet, will have
to put more thought into it.
On Fri, 3 Sep 2010 17:05:19 -0400, Sigurd Hermansen <HERMANS1@WESTAT.COM>
>I suspect that you have SAS/ACCESS OLEdb connections to a MS SQL Server
database. The LIBNAME XXX OLEDB ....; statement appears to let you set
data types using a DBTYPE= or DBSASTYPE = option:
>These date options (p. 22) look promising:
>DBTYPE_DBTIMESTAMP and DBTYPE_DATE
>DATETIMEm.n, where m depends on precision
>and n depends on scale
>"The following table shows the default data types that the SAS/ACCESS
>OLE DB uses when creating DBMS tables.
>Table 1.5 Default OLE DB Output Data Types
>SAS Variable Format Default OLE DB Data Type
>DBTYPE_R8 or DBTYPE_NUMERIC using m.n
>if the DBMS allows it
>$n. DBTYPE_STR using n
>date formats DBTYPE_DBDATE
>time formats DBTYPE_DBTIME
>datetime formats DBTYPE_DBTIMESTAMP
>The SAS/ACCESS interface to OLE DB allows nondefault data types to be
>with the DBTYPE= data set option."
>The problem that you are having seems to be related to a setting in the
OLEdb middleware since your database has a date data type and SAS has a
date format that operates on a range of numbers. The SAS "date" value
amounts to nothing more than a number. For some reason the middleware is
converting the SQL Server date value to number on the datetime scale
instead of the date scale and assigning a datetime format instead of a
>From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
>Sent: Friday, September 03, 2010 10:35 AM
>Subject: SQL server dates not date times
>Short version of question (which yes, I've seen similar in the archives):
>How can I get DATE variables from SQL server 2008 into SAS as dates
>(rather than as date-times)? Without specifying a conversion for each
>variable (e.g. datepart or whatever).
>Suppose we have a clinical trial database which is happpily growing. Data
>are stored in SQL server 2008. Database has hundreds of tables (say, one
>table/view per case report form per trial), and some of the columns are
>defined in SQL server as dates. [nb: as I understand it, SQL server 2008
>introduced a new DATE type, so these are really stored as dates, not date-
>times (http://msdn.microsoft.com/en-us/library/bb630352.aspx) ]
>We want our SAS programmers to be able to hit the database using
>SAS/ACCESS or PROC SQL to select * from a view and pull a table into SAS.
>When we do this now, the date columns from the SQL server database come
>into SAS as date-time variables.
>Yes, we could tell everyone how "easy" it is to convert datetimes to dates
>(using datepart or whatever). But that means every time someone pulls a
>table they need to know which columns are dates, and write the conversion
>themselves (could be a fun macro to write, but I'm hoping to avoid even
>that). And when they forget to do that, a bunch of utility code which
>expects standard elements like DOB to be dates will start breaking.
>I've seen lots in the archives about this issue, but mostly the responses
>have been to explain date-times vs dates, and how to convert, which I
>understand. But since SQL server 2008 has actual DATE columns, it feels
>reasonable to expect SAS to import these as date variables.
>A colleague asked tech support about this issue. They pointed him to:
>Which seems to say that if we were accessing an Oracle database, we could
>set a global SASDATEFMT option in config file to have all Oracle dates
>come into SAS as SAS dates (rather than date times). This is exactly what
>we want. Unfortunately the first note ends by saying that SAS/ACCESS for
>databases other than Oracle "may offer this global support in a future
>release (i.e. 9.1.3 SP3 or later)." Well, it's later than 9.1.3, so would
>love this global option.
>As I hinted above, if there isn't a way to flip a global switch somewhere
>to have SAS import SQL server dates as SAS dates, my next thought is to
>write a macro %downloadfromsql(data=) that would identify the sql server
>columns that are defined as dates (using sql server equivalent of
>dictionary tables), and generate the SQL statement to convert each of the
>date columns to date variables when SAS pulls them down. But seems like a
>hassle of a workaround. It's just hard to believe that everyone who is
>using SAS to access dates in SQL server is using such a workaround. But I
>guess if SQL server really only created the DATE type in SQL server 2008,
>up until that point there was no other option, so there might not have
>been pressure on SAS for this functionality.
>Okay, long post (making up for too many years of not posting ?). Best
>wishes to all for a happy weekend (long weekend for US folks, hopefully
>hurricane-free here on the East Coast).