<?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: How to apply DATE macro while connect to ODBC using proc sql in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602231#M174322</link>
    <description>&lt;P&gt;Thanks, Tom.&lt;/P&gt;</description>
    <pubDate>Wed, 06 Nov 2019 21:41:32 GMT</pubDate>
    <dc:creator>Bikila</dc:creator>
    <dc:date>2019-11-06T21:41:32Z</dc:date>
    <item>
      <title>How to apply DATE macro while connect to ODBC using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602203#M174313</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;I was writing DATE macro&amp;nbsp; while connecting to SQL server using ODBC.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I wrote the following code:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
START_DATE= intnx ('month',today(),-2,'B'); 
END_DATE= intnx ('month',today(),-1,'E'); 
call symput ('S_DATE', START_DATE);
Call Symput ('E_DATE', END_DATE);
run;
proc sql;
connect to odbc as ALIAS
(datasrc=SQLSERVER user=USER password=PWD);
create table DATASET as
select * from connection to ALIAS
(SELECT distinct *
FROM DATABASE.dbo.TABLE
WHERE  DOS_FROM &amp;gt;= &amp;amp;S_DATE
)
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I got the following error:&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000"&gt;ERROR: CLI describe error: [Microsoft][SQL Server Native Client 11.0][SQL Server]Operand type clash: date is incompatible with &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT color="#800000"&gt;smallint : [Microsoft][SQL Server Native Client 11.0][SQL Server]Statement(s) could not be prepared.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Note: the variable&amp;nbsp;&lt;CODE class=" language-sas"&gt;DOS_FROM in the sql database is a format of date9.(DDMMMYYYY type).&amp;nbsp;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000000"&gt;Any help is appreciated.&amp;nbsp;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800000"&gt;&lt;FONT color="#000000"&gt;Regards&lt;/FONT&gt;,&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 20:24:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602203#M174313</guid>
      <dc:creator>Bikila</dc:creator>
      <dc:date>2019-11-06T20:24:00Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply DATE macro while connect to ODBC using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602207#M174314</link>
      <description>&lt;P&gt;Try :&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
START_DATE= intnx ('month',today(),-2,'B'); 
END_DATE= intnx ('month',today(),-1,'E'); 
call symputx ('S_DATE', quote(put(START_DATE,yymmddd10.)));
Call Symputx ('E_DATE', quote(put(END_DATE,yymmddd10.))); ;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Nov 2019 20:35:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602207#M174314</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-11-06T20:35:49Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply DATE macro while connect to ODBC using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602211#M174318</link>
      <description>&lt;P&gt;What syntax does your remote database want?&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is an example to generate strings like:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;'2019-11-06'&lt;/CODE&gt;&lt;/PRE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data _null_;
  START_DATE= intnx ('month',today(),-2,'B'); 
  END_DATE= intnx ('month',today(),-1,'E'); 
  call symputx ('S_DATE', quote(put(START_DATE,yymmdd10.),"'"));
  call symputx ('E_DATE', quote(put(END_DATE,yymmdd10.),"'"));
run;
proc sql;
connect to odbc as ALIAS (datasrc=SQLSERVER user=USER password=PWD);
create table DATASET as
  select * from connection to ALIAS
  (SELECT distinct *
   FROM DATABASE.dbo.TABLE 
   WHERE  DOS_FROM &amp;gt;= DATE &amp;amp;S_DATE
  )
;
QUIT;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Nov 2019 20:49:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602211#M174318</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-11-06T20:49:54Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply DATE macro while connect to ODBC using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602231#M174322</link>
      <description>&lt;P&gt;Thanks, Tom.&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 21:41:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602231#M174322</guid>
      <dc:creator>Bikila</dc:creator>
      <dc:date>2019-11-06T21:41:32Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply DATE macro while connect to ODBC using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602251#M174334</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/298553"&gt;@Bikila&lt;/a&gt;:&lt;/P&gt;
&lt;P&gt;You don't need to write a macro. The macro variables you need can be obtained using the following macro expressions:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let sdate = %str(%')%sysfunc(intnx(mon,%sysfunc(date()),-2,B),yymmdd10)%str(%') ;                                                      
%let edate = %str(%')%sysfunc(intnx(mon,%sysfunc(date()),-1,E),yymmdd10)%str(%') ; 
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you %PUT them in the log, you'll see:&lt;/P&gt;
&lt;PRE&gt;%put &amp;amp;=sdate &amp;amp;=edate ;
SDATE='2019-09-01' EDATE='2019-10-31'
&lt;/PRE&gt;
&lt;P&gt;And you don't even have to assign the expressions to macro variables, as they can be used directly in the query, like so:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DOS_FROM &amp;gt;= %str(%')%sysfunc(intnx(mon,%sysfunc(date()),-2,B),yymmdd10)%str(%')
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;OTOH, since you're using SQL Server specific language via explicit Pass-Thru, you can use SQL Server functions GETDATE(), DATEADD, CAST, EOMONTH, and so on to generate your shifted dates in the query itself.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Kind regards&lt;/P&gt;
&lt;P&gt;Paul D.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 22:09:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602251#M174334</guid>
      <dc:creator>hashman</dc:creator>
      <dc:date>2019-11-06T22:09:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to apply DATE macro while connect to ODBC using proc sql</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602267#M174342</link>
      <description>&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Nov 2019 23:04:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-apply-DATE-macro-while-connect-to-ODBC-using-proc-sql/m-p/602267#M174342</guid>
      <dc:creator>Bikila</dc:creator>
      <dc:date>2019-11-06T23:04:59Z</dc:date>
    </item>
  </channel>
</rss>

