<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Datetime in a SQL Passthrough in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323209#M271167</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37860"&gt;@aj34321&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code like:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let transfer_start_time = %sysfunc(datetime()); populates SAS macro variable &amp;amp;transfer_start_time with a SAS DateTime value. Right now when I run it this value would be:&amp;nbsp;1799530675.664&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;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 &amp;nbsp;SYSDATETIME() &lt;A href="https://msdn.microsoft.com/en-us/library/bb630353.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/bb630353.aspx&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Sun, 08 Jan 2017 10:46:51 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2017-01-08T10:46:51Z</dc:date>
    <item>
      <title>Datetime in a SQL Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323194#M271163</link>
      <description>&lt;P&gt;Hi All,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Request if someone can help me on the below error. I'm simply storing start &amp;amp; end time in a macro variable and&amp;nbsp;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;ERROR: CLI execute error: [SAS/ACCESS to SQL Server][ODBC SQL Server Wire Protocol driver][Microsoft SQL Server]Arithmetic overflow &lt;BR /&gt;error converting expression to data type datetime. : [SAS/ACCESS to SQL Server][ODBC SQL Server Wire Protocol &lt;BR /&gt;driver][Microsoft SQL Server]The statement has been terminated.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;%let transfer_start_time = %sysfunc(datetime());&lt;BR /&gt; /*sas code here*/&lt;BR /&gt; %let transfer_end_time = %sysfunc(datetime());&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;proc sql;&lt;BR /&gt; connect to sqlsvr (&amp;amp;sqlconn_stg);&lt;BR /&gt; execute &lt;BR /&gt; ( update schema.table&lt;BR /&gt; set&lt;BR /&gt;StartDate = &amp;amp;transfer_start_time,&lt;BR /&gt;EndDate = &amp;amp;transfer_end_time,&lt;BR /&gt;RecordCount = 10000,&lt;BR /&gt;StatusCode = 'X1'&lt;BR /&gt; where &lt;BR /&gt;TransferId = 1010 and &lt;BR /&gt;StatusCode = 'XP'&lt;BR /&gt; ) by sqlsvr;&lt;BR /&gt; disconnect from sqlsvr;&lt;BR /&gt; quit;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Anil&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 06:59:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323194#M271163</guid>
      <dc:creator>aj34321</dc:creator>
      <dc:date>2017-01-08T06:59:41Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime in a SQL Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323197#M271164</link>
      <description>&lt;P&gt;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.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;set&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;StartDate = &lt;STRONG&gt;&amp;amp;transfer_start_time&lt;/STRONG&gt;,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EndDate = &lt;STRONG&gt;&amp;amp;transfer_end_time&lt;/STRONG&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;What strings do above two macro variable contain - and is it valid SQL Srv syntax?&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 07:28:20 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323197#M271164</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-08T07:28:20Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime in a SQL Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323199#M271165</link>
      <description>&lt;P&gt;Hi Patrick,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Below is what im assigning into macro variable.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;%let transfer_start_time = %sysfunc(datetime());&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;/*sas code here*/&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;%let transfer_end_time = %sysfunc(datetime());&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anil&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 07:48:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323199#M271165</guid>
      <dc:creator>aj34321</dc:creator>
      <dc:date>2017-01-08T07:48:06Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime in a SQL Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323200#M271166</link>
      <description>&lt;P&gt;Check the value of those macro variables. Do they look &lt;STRONG&gt;exactly&lt;/STRONG&gt; like what you would hard code in MS SQL server? I highly suspect not.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The key to macro code is make it work first without macro variables and then create the macro portions necessary.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 07:56:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323200#M271166</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-01-08T07:56:26Z</dc:date>
    </item>
    <item>
      <title>Re: Datetime in a SQL Passthrough</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323209#M271167</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/37860"&gt;@aj34321&lt;/a&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Code like:&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;%let transfer_start_time = %sysfunc(datetime()); populates SAS macro variable &amp;amp;transfer_start_time with a SAS DateTime value. Right now when I run it this value would be:&amp;nbsp;1799530675.664&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;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 &amp;nbsp;SYSDATETIME() &lt;A href="https://msdn.microsoft.com/en-us/library/bb630353.aspx" target="_blank"&gt;https://msdn.microsoft.com/en-us/library/bb630353.aspx&lt;/A&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;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.&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 08 Jan 2017 10:46:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Datetime-in-a-SQL-Passthrough/m-p/323209#M271167</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2017-01-08T10:46:51Z</dc:date>
    </item>
  </channel>
</rss>

