<?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: passing variable to oracle query in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663462#M198054</link>
    <description>&lt;P&gt;The Oracle SQL interpreter does not recognize stuff in double quotes as constants, but as identifiers. So you will have to get your macro values in single quotes, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _NULL_;
 call symputx('date1',cats("'",put(intnx('month',today(),0),date9.),"'"));
 call symputx('date2',cats("'",put(intnx('month',today(),1),date9.),"'"));
Run;
%put &amp;amp;date1;
%put &amp;amp;date2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can the use that in the query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
&amp;amp;oraconnect;
execute (create table bc as
select      
a.key_num,
from warehouse_gbr.vtb_acct a

where a.dat_chrg_off &amp;gt;= to_date(&amp;amp;date1,'DDMMYYYY')
and a.dat_chrg_off &amp;lt; to_date(&amp;amp;date2,'DDMMYYYY')

order by a.key_num)
by ora ;
disconnect from ora;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I am not quite sure about the second parameter to your TO_DATE function, should it not be 'DDMONYYYY'?&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jun 2020 12:47:14 GMT</pubDate>
    <dc:creator>s_lassen</dc:creator>
    <dc:date>2020-06-19T12:47:14Z</dc:date>
    <item>
      <title>passing variable to oracle query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663448#M198043</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this piece of code:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;proc sql;
&amp;amp;oraconnect;
execute (create table bc as
select      
a.key_num,
from warehouse_gbr.vtb_acct a

where a.dat_chrg_off &amp;gt;= to_date('01MAY2020','DDMMYYYY')
and a.dat_chrg_off &amp;lt; to_date('01JUN2020','DDMMYYYY')

order by a.key_num)
by ora ;
disconnect from ora;
quit;&lt;/PRE&gt;&lt;P&gt;and I am trying to pass those variables date1 instead of May date and date2 instead of June date (see below).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Data _NULL_;
 call symput('date1',put(intnx('month',today(),0),date9.));
 call symput('date2',put(intnx('month',today(),1),date9.));
Run;
%put &amp;amp;date1;
%put &amp;amp;date2;&lt;/PRE&gt;&lt;P&gt;Is there a way to do this?&amp;nbsp; I tried multiple things and they do not work.&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;</description>
      <pubDate>Fri, 19 Jun 2020 11:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663448#M198043</guid>
      <dc:creator>jepafob</dc:creator>
      <dc:date>2020-06-19T11:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: passing variable to oracle query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663462#M198054</link>
      <description>&lt;P&gt;The Oracle SQL interpreter does not recognize stuff in double quotes as constants, but as identifiers. So you will have to get your macro values in single quotes, e.g.:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data _NULL_;
 call symputx('date1',cats("'",put(intnx('month',today(),0),date9.),"'"));
 call symputx('date2',cats("'",put(intnx('month',today(),1),date9.),"'"));
Run;
%put &amp;amp;date1;
%put &amp;amp;date2;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;You can the use that in the query:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
&amp;amp;oraconnect;
execute (create table bc as
select      
a.key_num,
from warehouse_gbr.vtb_acct a

where a.dat_chrg_off &amp;gt;= to_date(&amp;amp;date1,'DDMMYYYY')
and a.dat_chrg_off &amp;lt; to_date(&amp;amp;date2,'DDMMYYYY')

order by a.key_num)
by ora ;
disconnect from ora;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;But I am not quite sure about the second parameter to your TO_DATE function, should it not be 'DDMONYYYY'?&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jun 2020 12:47:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663462#M198054</guid>
      <dc:creator>s_lassen</dc:creator>
      <dc:date>2020-06-19T12:47:14Z</dc:date>
    </item>
    <item>
      <title>Re: passing variable to oracle query</title>
      <link>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663463#M198055</link>
      <description>There is current_date and add months feature in oracle can’t you use them? Can’t you put double quotes around macro variables to_date(“&amp;amp;date1.”,'DDMMYYYY').&lt;BR /&gt;What did you try and did not work.</description>
      <pubDate>Fri, 19 Jun 2020 12:51:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/passing-variable-to-oracle-query/m-p/663463#M198055</guid>
      <dc:creator>smantha</dc:creator>
      <dc:date>2020-06-19T12:51:15Z</dc:date>
    </item>
  </channel>
</rss>

