BookmarkSubscribeRSS Feed
aj34321
Quartz | Level 8

Hi All, 

 

Request if someone can help me on the below error. I'm simply storing start & end time in a macro variable and passing it into an SQL passthrough to update the start and end times into sql table. What should i change it, so that the table is updated for the start and end times.

 

 

ERROR: CLI execute error: [SAS/ACCESS to SQL Server][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Arithmetic overflow
error converting expression to data type datetime. : [SAS/ACCESS to SQL Server][ODBC SQL Server Wire Protocol
driver][Microsoft SQL Server]The statement has been terminated.

 

%let transfer_start_time = %sysfunc(datetime());
/*sas code here*/
%let transfer_end_time = %sysfunc(datetime());

 

 

proc sql;
connect to sqlsvr (&sqlconn_stg);
execute
( update schema.table
set
StartDate = &transfer_start_time,
EndDate = &transfer_end_time,
RecordCount = 10000,
StatusCode = 'X1'
where
TransferId = 1010 and
StatusCode = 'XP'
) by sqlsvr;
disconnect from sqlsvr;
quit;

 

Thanks,

 

Anil

 

4 REPLIES 4
Patrick
Opal | Level 21

The code in your pass-through block must be valid SQL Srv syntax. The SAS macro variable must therefore resolve to a string which is such valid syntax.

 

set
StartDate = &transfer_start_time,
EndDate = &transfer_end_time,

 

What strings do above two macro variable contain - and is it valid SQL Srv syntax?

aj34321
Quartz | Level 8

Hi Patrick,

 

Below is what im assigning into macro variable.

%let transfer_start_time = %sysfunc(datetime());
/*sas code here*/
%let transfer_end_time = %sysfunc(datetime());

 

Thanks,

 

Anil

 

Reeza
Super User

Check the value of those macro variables. Do they look exactly like what you would hard code in MS SQL server? I highly suspect not. 

 

The key to macro code is make it work first without macro variables and then create the macro portions necessary. 

 

 

Patrick
Opal | Level 21

@aj34321

Code like: %let transfer_start_time = %sysfunc(datetime()); populates SAS macro variable &transfer_start_time with a SAS DateTime value. Right now when I run it this value would be: 1799530675.664

 

Each database deals with Dates, DateTimes and TimeStamps differently. You can't just pass in a SAS DateTime value in a pass-through SQL block (which is in data base native SQL) as then the database doesn't have any information how to convert this SAS value to the database specific representation.

 

You need either to look up how to pass in a STRING - and populate the SAS Macro variable with such a string - or if you just want to pass in the system time equivalent of what you would get with the SAS Datetime() function then use the equivalant database function in your pass-through SQL block. For a SQL Server DateTime column this appears to be function  SYSDATETIME() https://msdn.microsoft.com/en-us/library/bb630353.aspx

 

I haven't worked a lot with SQL Server so I don't know if function SYSDATETIME() will resolve for every single row or only once. I'm sure SQL Server has implemented options for both cases and it's just a question of RTM to figure out the right syntax.

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 4 replies
  • 2340 views
  • 0 likes
  • 3 in conversation