<?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: Macro Loop error in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347120#M80134</link>
    <description>&lt;P&gt;Thank you for the reply...I changed the date format in SAS and it worked.&lt;/P&gt;</description>
    <pubDate>Tue, 04 Apr 2017 17:14:14 GMT</pubDate>
    <dc:creator>Kalai2008</dc:creator>
    <dc:date>2017-04-04T17:14:14Z</dc:date>
    <item>
      <title>Macro Loop error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347098#M80127</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Can somebody help me..I was trying to pass 20 dates in a loop inside a oracle query...But getting oracle error&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;ERROR: ORACLE execute error: ORA-01843: not a valid month.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%global vardate;&lt;BR /&gt;%let vardate=%str(work.cdate);cdate contains 20 dates (30NOV2016) that I need to run in a loop&lt;/P&gt;&lt;P&gt;%macro rep(first,last);&lt;BR /&gt;data listdate ;&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set &amp;amp;vardate (firstobs = &amp;amp;first OBS = &amp;amp;last);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;proc sql noprint;&lt;BR /&gt;select distinct "'"||trim(left(put(cs_date,8.)))||"'"&amp;nbsp; into: CLISTdate (I tried 10. ERROR: ORACLE execute error: ORA-01861: literal does not match format string.)&lt;BR /&gt;from listdate;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc Sql;&lt;BR /&gt;connect to oracle...&lt;BR /&gt;create table...&lt;BR /&gt;(&lt;BR /&gt;select *&lt;BR /&gt;from..where..&lt;BR /&gt;and c.date= &amp;amp;CLISTdate&lt;BR /&gt;)&lt;BR /&gt;proc sql;&lt;BR /&gt;select count(distinct cs_date) into: count1&lt;BR /&gt;from &amp;amp;vardate;&lt;BR /&gt;quit;&lt;/P&gt;&lt;P&gt;%put &amp;amp;count1;&lt;/P&gt;&lt;P&gt;%macro act;&lt;BR /&gt;%do i=0 %to &amp;amp;count1 %by 100;&amp;nbsp;&lt;BR /&gt;%put first=%eval(&amp;amp;i);&lt;BR /&gt;%if &amp;amp;i. LT &amp;amp;count1 %then %goto continue;&lt;BR /&gt;%else %if &amp;amp;i. GE &amp;amp;count1 %then %goto leave;&lt;BR /&gt;%continue:&lt;BR /&gt;%rep(%eval(&amp;amp;i+1), %eval(&amp;amp;i+100))&lt;BR /&gt;%end;&lt;BR /&gt;%leave:&lt;BR /&gt;%put&lt;BR /&gt;%mend;&lt;BR /&gt;%act&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for the help..&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 16:06:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347098#M80127</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-04-04T16:06:56Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347114#M80133</link>
      <description>&lt;P&gt;First get the ORACLE syntax that works. Then figure out how to generate the code using macro logic and/or macro variables.&lt;/P&gt;
&lt;P&gt;If you have your dates in DATE9 format&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let datelist=30NOV2016 31DEC2016 31JAN2017;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;then to use them in SAS code you will need to convert them in date literals like "30NOV2016"d.&lt;/P&gt;
&lt;P&gt;I suspect that to use them in ORACLE at a minimum you will need enclose them in single quotes. You might even need to convert them into a different display format for dates like '2016-11-30' instead of '30NOV2016'.&lt;/P&gt;
&lt;P&gt;If you just want to loop over a space delimited list of words that are in a macro variable then you could use logic like this. It needs to be inside of a macro to be able to use %DO loop.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%do i=1 %to %sysfunc(countw(&amp;amp;datelist));
  %let datetext=%scan(&amp;amp;datelist,&amp;amp;i);
  %let sasdate="&amp;amp;datetext"d ;
  %let oracledate = %unquote(%str(%')&amp;amp;datetext%str(%'));
  .....
%end;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 16:43:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347114#M80133</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-04-04T16:43:31Z</dc:date>
    </item>
    <item>
      <title>Re: Macro Loop error</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347120#M80134</link>
      <description>&lt;P&gt;Thank you for the reply...I changed the date format in SAS and it worked.&lt;/P&gt;</description>
      <pubDate>Tue, 04 Apr 2017 17:14:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Macro-Loop-error/m-p/347120#M80134</guid>
      <dc:creator>Kalai2008</dc:creator>
      <dc:date>2017-04-04T17:14:14Z</dc:date>
    </item>
  </channel>
</rss>

