Date: Wed, 27 Jan 2010 14:37:47 -0800
Reply-To: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Sender: "SAS(r) Discussion" <SAS-L@LISTSERV.UGA.EDU>
From: "Terjeson, Mark" <Mterjeson@RUSSELL.COM>
Subject: Re: SQL Server ODBC Date issue
Content-Type: text/plain; charset="us-ascii"
I'm going to give you two alternatives,
a couple caveats and slightly different
rede on two words.
SAS has two date types, DATE and DATETIME.
SQLSvr only has one date time, DATETIME.
Therefore, your two words "problem" and
"fix" I would revamp as "a difference" and
Of course, if you were using DATETIME types
in SAS you would not need to "convert" the
type from DATETIME to DATE. But it is perfectly
fine and we all have many programs where we
prefer to use DATE, so we convert from DATETIME
to DATE just as you have.
Your example below is, of course, a very typical
way in SAS to process this. The other method is
that you can combine it all into the first SQL
query. As you know, the text inside the parentheses
is the PASS-THROUGH text that gets shipped off to
the SQL Server box to get run there on the SQL
Server box so it must be in SQL Server syntax.
Now, outside the parentheses, we have SAS SQL
syntax, so you could replace the wildcard asterisk
with the individual column names and you could
wrap the date column with the DATEPART() function
thereby combining both tasks into one step.
Now for the caveats, if your SAS query which
includes the pass-through gets a little too
complex and you start doing joins or significant
column manipulation, of course, joins between
the remote tables and local tables will start
doing the row-by-row joins over-the-wire and
your performance will get bad quick.
Obviously, joins between remote and local table have
to do everything across the i/o wire (which is the
slowest link in the chain), but also a lot of column
manipulation and expression handling on the SAS side
with only the records coming from the remote SQL Svr
also can bog down the i/o dump from SQL Svr as caching
and traffic-cop-i/o-handling are less proficient than
just a quick dump of records from the remote box.
In most situations, not only is it more straight
forward to keep them separate, but you typically
gain the best performance by keeping the download
from SQL Server very simple such as "SELECT *"
and then do all the subsequent joins and manipulation
in SAS because SAS is so much faster. So for plug-n-play
developing and for performance, you will find many of
us doing exactly what you have already!
Hope this is helpful.
Investment Business Intelligence
Investment Management & Research
Global Leaders in Multi-Manager Investing
From: SAS(r) Discussion [mailto:SAS-L@LISTSERV.UGA.EDU] On Behalf Of
Sent: Wednesday, January 27, 2010 8:35 AM
Subject: SQL Server ODBC Date issue
I am importing data from SQL server 2000 into SAS. I always have
problem with date when I do that and I run the second statement given
below to fix dates. Is there a way to combine these two in one step.
dm log 'clear';
CONNECT TO ODBC (DSN=Prod');
CREATE TABLE USAlphas AS
SELECT * FROM CONNECTION TO ODBC
SELECT Ticker, Name_Short, Snapshot_Date, Alpha
format AsOfDt YYMMDD10.;