<?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: proc sql to oracle date with date macro variable in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375182#M11374</link>
    <description>&lt;P&gt;Once you get the quote issue resolved, it is conceivable that you may need to fix the variable names. &amp;nbsp;This version would be consistent with trying to use &amp;amp;curdat_2m within the SQL code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;curdat_2 = intnx(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'Month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;"&amp;amp;sysdate"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'s'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;symput (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'curdat_2m'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,put(curdat_2,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;yymmddn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 12 Jul 2017 02:18:43 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2017-07-12T02:18:43Z</dc:date>
    <item>
      <title>proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375175#M11372</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I am trying to plug in a date macro variable (&amp;amp;curdat_2m as in the code below)&amp;nbsp;in my query, but somehow I got no rows. When I used specific date like 20070515, the query ran fine. Can you see what problem with the where clause in the query? Thanks a lot!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt; curdat_2m = intnx(&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'Month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;"&amp;amp;sysdate"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'s'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; symput (&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'curdat_2m'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,put(curdat_2m,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymmddn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;PROC&lt;/STRONG&gt;&lt;/FONT&gt; &lt;STRONG&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;SQL&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CONNECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TO&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ORACLE( ...);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;CREATE&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;TABLE&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; new_tbl &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;as&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;SELECT&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; * &lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; CONNECTION TO ORACLE&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;(&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;select&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;distinct&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; MBR_ID, FST_NM, LST_NM, DOB, ZIP&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;from&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; DB.MBR_TBL &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;where&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;'&amp;amp;curdat_2m.'&lt;/FONT&gt; &lt;FONT color="#008000" face="Courier New" size="3"&gt;/*if using '20070515', the query generates a number of rows*/&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;between&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; to_char(BEG_DT, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'YYYYMMDD'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) &lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;and&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; to_char(END_DT, &lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'YYYYMMDD'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;);&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;DISCONNECT&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;FROM&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; ORACLE;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;QUIT&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&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="3"&gt;Thanks for the help!&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="arial,helvetica,sans-serif" size="3"&gt;Lizi&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 12:20:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375175#M11372</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2017-07-12T12:20:17Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375178#M11373</link>
      <description>&lt;P&gt;Macro variables don't resolve inside single quotes.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Shouldn't that be a variable name though and therefore not have quotes at all?&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 02:06:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375178#M11373</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2017-07-12T02:06:18Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375182#M11374</link>
      <description>&lt;P&gt;Once you get the quote issue resolved, it is conceivable that you may need to fix the variable names. &amp;nbsp;This version would be consistent with trying to use &amp;amp;curdat_2m within the SQL code:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;data&lt;/STRONG&gt;&lt;/FONT&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;_null_&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3"&gt;curdat_2 = intnx(&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'Month'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;"&amp;amp;sysdate"d&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,-&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;2&lt;/FONT&gt;&lt;/STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'s'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;);&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#0000ff"&gt;call&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;symput (&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#800080"&gt;'curdat_2m'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,put(curdat_2,&lt;/FONT&gt;&lt;FONT face="Courier New" size="3" color="#008080"&gt;yymmddn8.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)) ;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="Courier New" size="3" color="#000080"&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 02:18:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375182#M11374</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-12T02:18:43Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375183#M11375</link>
      <description>&lt;P&gt;Here is how you get the macro date to resolve but still use single quotes as I suspect Oracle will object to double quotes:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;where %str(%')&amp;amp;curdat_2m.%str(%') between ........&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 12 Jul 2017 02:31:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375183#M11375</guid>
      <dc:creator>SASKiwi</dc:creator>
      <dc:date>2017-07-12T02:31:44Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375215#M11376</link>
      <description>&lt;P&gt;You may need to go a step further:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;where &lt;FONT color="#339966"&gt;%unquote(&lt;/FONT&gt;%str(%')&amp;amp;curdat_2m.%str(%')&lt;FONT color="#339966"&gt;)&lt;/FONT&gt; between ......&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 06:21:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375215#M11376</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-07-12T06:21:19Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375284#M11379</link>
      <description>Thanks a lot, Kiwi! The code works!</description>
      <pubDate>Wed, 12 Jul 2017 12:20:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375284#M11379</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2017-07-12T12:20:53Z</dc:date>
    </item>
    <item>
      <title>Re: proc sql to oracle date with date macro variable</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375285#M11380</link>
      <description>&lt;P&gt;Thanks a lot, Astounding! This code solve my problem too!&lt;/P&gt;</description>
      <pubDate>Wed, 12 Jul 2017 12:23:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/proc-sql-to-oracle-date-with-date-macro-variable/m-p/375285#M11380</guid>
      <dc:creator>lizzy28</dc:creator>
      <dc:date>2017-07-12T12:23:57Z</dc:date>
    </item>
  </channel>
</rss>

