<?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: SAS / SQL Passthru with CONVERT DATEADD and DATEDIFF function examples in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/SAS-SQL-Passthru-with-CONVERT-DATEADD-and-DATEDIFF-function/m-p/547925#M8459</link>
    <description>&lt;P&gt;Greetings 15GreyGoose.&amp;nbsp; i pass most of my queries from SAS to the server hosting the data.&amp;nbsp; by doing this, you can use just about any compliant SQL Statement (in my experience).&amp;nbsp; the only common exception for me is the use of '--' for comment code in SQL Server.&amp;nbsp; SAS does not seem to like that here.&amp;nbsp; i suggest using block style commenting:&amp;nbsp; /* comments */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;here is a basic template you can use:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CONNECT TO ODBC as Alias
    (DATAsrc="DSN" authdomain=IfOneIsSetUp);
&amp;nbsp;
   CREATE TABLE work.thing  AS 
   SELECT *
      FROM CONNECTION TO Alias 
(
/*SQL Code*/

SELECT Convert(Date,DATEADD(MONTH, DATEDIFF(MONTH, -1,  APP_DATE_AJUDICATED )+0, -1)) FROM YourDbTableName
);
&amp;nbsp;
   DISCONNECT FROM Alias;
QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you will need to know the DSN for the remote server hosting the data.&amp;nbsp; you might be able to find the DSN by right click the Libname under libraries.&amp;nbsp; you will also need credentials to connect, we use an authodomain, but something like this could work as well:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;(noprompt = "server=ServerName; UID=UserId; pwd=UserPassword;DRIVER=SQL Server; DATABASE = DatabaseNameOnServer" )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 02 Apr 2019 15:29:36 GMT</pubDate>
    <dc:creator>utrocketeng</dc:creator>
    <dc:date>2019-04-02T15:29:36Z</dc:date>
    <item>
      <title>SAS / SQL Passthru with CONVERT DATEADD and DATEDIFF function examples</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-SQL-Passthru-with-CONVERT-DATEADD-and-DATEDIFF-function/m-p/547922#M8458</link>
      <description>&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Hi!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;I've been asked to update some old SQL code and re-write it in SAS 9.4.&amp;nbsp; The old SQL query has SQL Convert, DateAdd, and DateDiff functions that are not supported in SAS and I've been struggling with this for most of the day.&amp;nbsp; I'm using Proc SQL / an explicit pass through to get the results into&amp;nbsp;SAS 9.4&amp;nbsp;for me to do what I need to do with the data.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;Specifically, here are some lines of exact code that I'm trying to manipulate.&amp;nbsp; I believe it is a combination of SAS Input functions along with whatever the SAS equivalent is for the SQL DateAdd and SQL DateDiff:&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;Old SQL Syntax Line #1):&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;Convert(Date, APP_DATE_AJUDICATED)&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;New SAS &lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;replacement syntax&lt;/SPAN&gt;&lt;/FONT&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;:&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;Old SQL Syntax Line #2:&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;Convert(Date,DATEADD(MONTH, DATEDIFF(MONTH, -1,&amp;nbsp; APP_DATE_AJUDICATED )+0, -1))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;New SAS replacement syntax SAS:&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;Old SQL Syntax Line #3:&amp;nbsp; Convert(Date, DateAdd(D,1, APP_DATE_AJUDICATED ))&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="2"&gt;&lt;SPAN style="background: white; color: black; font-family: &amp;quot;Courier New&amp;quot;; font-size: 12pt;"&gt;New SAS replacement syntax:&amp;nbsp; &lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Arial"&gt;I'm a bit over my head and haven't been able to make much progress on this this morning so I'm turning to the SAS community for assistance!&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;Please help!,&lt;/P&gt;&lt;P&gt;Andrew&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 15:27:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-SQL-Passthru-with-CONVERT-DATEADD-and-DATEDIFF-function/m-p/547922#M8458</guid>
      <dc:creator>15GreyGoose</dc:creator>
      <dc:date>2019-04-02T15:27:17Z</dc:date>
    </item>
    <item>
      <title>Re: SAS / SQL Passthru with CONVERT DATEADD and DATEDIFF function examples</title>
      <link>https://communities.sas.com/t5/New-SAS-User/SAS-SQL-Passthru-with-CONVERT-DATEADD-and-DATEDIFF-function/m-p/547925#M8459</link>
      <description>&lt;P&gt;Greetings 15GreyGoose.&amp;nbsp; i pass most of my queries from SAS to the server hosting the data.&amp;nbsp; by doing this, you can use just about any compliant SQL Statement (in my experience).&amp;nbsp; the only common exception for me is the use of '--' for comment code in SQL Server.&amp;nbsp; SAS does not seem to like that here.&amp;nbsp; i suggest using block style commenting:&amp;nbsp; /* comments */&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;here is a basic template you can use:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;PROC SQL;
   CONNECT TO ODBC as Alias
    (DATAsrc="DSN" authdomain=IfOneIsSetUp);
&amp;nbsp;
   CREATE TABLE work.thing  AS 
   SELECT *
      FROM CONNECTION TO Alias 
(
/*SQL Code*/

SELECT Convert(Date,DATEADD(MONTH, DATEDIFF(MONTH, -1,  APP_DATE_AJUDICATED )+0, -1)) FROM YourDbTableName
);
&amp;nbsp;
   DISCONNECT FROM Alias;
QUIT;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;you will need to know the DSN for the remote server hosting the data.&amp;nbsp; you might be able to find the DSN by right click the Libname under libraries.&amp;nbsp; you will also need credentials to connect, we use an authodomain, but something like this could work as well:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;(noprompt = "server=ServerName; UID=UserId; pwd=UserPassword;DRIVER=SQL Server; DATABASE = DatabaseNameOnServer" )&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Apr 2019 15:29:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/SAS-SQL-Passthru-with-CONVERT-DATEADD-and-DATEDIFF-function/m-p/547925#M8459</guid>
      <dc:creator>utrocketeng</dc:creator>
      <dc:date>2019-04-02T15:29:36Z</dc:date>
    </item>
  </channel>
</rss>

