<?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 do loop from one date to another date? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570417#M160838</link>
    <description>Can you please comment your code with what you think is happening and which parts you're trying to change?&lt;BR /&gt;&lt;BR /&gt;For example, this section does nothing at all:&lt;BR /&gt;&lt;BR /&gt;Data pl&amp;amp;yymm..POLA_clm_agg_&amp;amp;yymm.;&lt;BR /&gt;set pl&amp;amp;yymm..POLA_clm_agg_&amp;amp;yymm.;&lt;BR /&gt; &lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I suggest checking Example 11 from the documentation here: &lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I would highly recommend a few other changes: &lt;BR /&gt;&lt;BR /&gt;1. Calculate your dates in a data _null_ step, much easier and use actual SAS dates, not numerical variables. &lt;BR /&gt;2. Look up CALL EXECUTE to execute the macro for multiple intervals directly from the data _null_ step (Step 1). &lt;BR /&gt;&lt;BR /&gt;</description>
    <pubDate>Tue, 02 Jul 2019 02:28:29 GMT</pubDate>
    <dc:creator>Reeza</dc:creator>
    <dc:date>2019-07-02T02:28:29Z</dc:date>
    <item>
      <title>How to do loop from one date to another date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570413#M160837</link>
      <description>&lt;P&gt;Hi all, facing some problems regarding to have a do loop to loop between date (only the month and year).&lt;/P&gt;&lt;P&gt;Plus can I extract the year and month while looping them?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have startyear, startmonth, endyear and endmonth for user to set according to their need.&lt;/P&gt;&lt;P&gt;For example I set the startyear and month is 2015 and 6, while the end is 2019 and 2.&lt;/P&gt;&lt;P&gt;Can I loop&amp;nbsp;&amp;nbsp;&lt;STRONG&gt; 6/2015, 7/2015 , 8/2015 ,...................., 1/2019, 2/2019&lt;/STRONG&gt; like this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The do loop I want to apply is only for the &lt;STRONG&gt;OS&lt;/STRONG&gt; which is on the last part in bold.&lt;/P&gt;&lt;P&gt;while the accyrfy and accmthfy in orange text is based on the year and the month&amp;nbsp; in the loop.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;my code is below:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; startyr=2015;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; startmth=6;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; endyr=2019;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; endmth=2;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; yymm=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;endyr*100+&amp;amp;endmth);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%macro&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date(startyr, startmth,endyr,endmth);&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;&lt;FONT face="Courier New" size="3"&gt;libname pl&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&lt;/FONT&gt; &lt;FONT color="#800080" face="Courier New" size="3"&gt;"\\kaiwksgh415thw5\Data\POLA\Claim\&amp;amp;endyr\&amp;amp;yymm\DBF"&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;Data pl&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&lt;STRONG&gt;.P&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;OLA_clm_agg_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&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;set pl&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&lt;STRONG&gt;.P&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;OLA_clm_agg_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&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;run;&lt;/P&gt;&lt;P&gt;PROC FORMAT;&lt;/P&gt;&lt;P&gt;value $ class&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'VEH'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'1'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'FIR'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'2'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'GMS'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'3'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'BON'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'3'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'HUL'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'3'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'PAC'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'4'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'TEL'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'5'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'WWC'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'5'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'LIA'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'6'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'CGO'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'7'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'ENG'&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;'8'&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;RUN;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;startmth=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&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;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accyr_fy1=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;startyr+1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accmth_fy1=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&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;%else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&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;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accyr_fy1=&amp;amp;startyr;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accmth_fy1=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;startmth+1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&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;%if&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; &amp;amp;endmth=&lt;/FONT&gt;&lt;STRONG&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;12&lt;/FONT&gt;&lt;/STRONG&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%then&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&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;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accyr_fy2=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;endyr+1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accmth_fy2=1;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&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;%else&lt;/FONT&gt; &lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%do&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;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accyr_fy2=&amp;amp;endyr;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accmth_fy2=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;endmth+1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%end&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;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accyrmth_fy1=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;accyr_fy1*100+&amp;amp;accmth_fy1);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%let&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; accyrmth_fy2=&lt;/FONT&gt;&lt;FONT color="#0000ff" face="Courier New" size="3"&gt;%eval&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;(&amp;amp;accyr_fy2*100+&amp;amp;accmth_fy2);&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;/*****************************OS*****************************/&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;PROC SQL;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;create table SMCD_OS_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; AS&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;SELECT put(zmajrsk,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;$class.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) as class, min(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;&lt;FONT color="#ff6600"&gt;accyrfy&lt;/FONT&gt;.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;-lossyr_fy,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;11&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;) as dev11yr,accyr_fy,accmth_fy,sum(zclmos) AS zclmos&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;FROM pl&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm..P&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;OLA_clm_agg_&amp;amp;&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;yymm.&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;where (accyr_fy*&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;100&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;+accmth_fy)&amp;lt;=(&amp;amp;&lt;/FONT&gt;&lt;FONT color="#ff6600" face="Courier New" size="3"&gt;accyrfy.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;*&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;100&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;+&amp;amp;&lt;/FONT&gt;&lt;FONT color="#ff6600" face="Courier New" size="3"&gt;ACCMTHFY.&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;)&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;GROUP BY class,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;2&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;3&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt;,&lt;/FONT&gt;&lt;FONT color="#008080" face="Courier New" size="3"&gt;4&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;order by accyr_fy,accmth_fy;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;quit;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;ods html&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;FONT face="Courier New" size="3"&gt;file=&lt;/FONT&gt;&lt;FONT color="#800080" face="Courier New" size="3"&gt;"\\kaiwksgh415thw5\Data\POLA\Claim\&amp;amp;endyr\&amp;amp;yymm\result\SMCD_mth_OS_FY_10DY_&amp;amp;yymm..html"&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;style=normal;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;proc print;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;　&lt;/P&gt;&lt;P&gt;&lt;FONT color="#000080" face="Courier New" size="3"&gt;&lt;STRONG&gt;%mend&lt;/STRONG&gt;&lt;/FONT&gt;&lt;FONT face="Courier New" size="3"&gt; date;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%&lt;STRONG&gt;&lt;I&gt;date&lt;/I&gt;&lt;/STRONG&gt;(&amp;amp;startyr, &amp;amp;startmth,&amp;amp;endyr,&amp;amp;endmth);&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;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 00:50:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570413#M160837</guid>
      <dc:creator>Kayla_Tan222</dc:creator>
      <dc:date>2019-07-02T00:50:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do loop from one date to another date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570417#M160838</link>
      <description>Can you please comment your code with what you think is happening and which parts you're trying to change?&lt;BR /&gt;&lt;BR /&gt;For example, this section does nothing at all:&lt;BR /&gt;&lt;BR /&gt;Data pl&amp;amp;yymm..POLA_clm_agg_&amp;amp;yymm.;&lt;BR /&gt;set pl&amp;amp;yymm..POLA_clm_agg_&amp;amp;yymm.;&lt;BR /&gt; &lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;I suggest checking Example 11 from the documentation here: &lt;BR /&gt;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/SAS-9-4-Macro-Language-Reference-Has-a-New-Appendix/ta-p/291716&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;I would highly recommend a few other changes: &lt;BR /&gt;&lt;BR /&gt;1. Calculate your dates in a data _null_ step, much easier and use actual SAS dates, not numerical variables. &lt;BR /&gt;2. Look up CALL EXECUTE to execute the macro for multiple intervals directly from the data _null_ step (Step 1). &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 02 Jul 2019 02:28:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570417#M160838</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-07-02T02:28:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to do loop from one date to another date?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570422#M160841</link>
      <description>&lt;P&gt;Let's clean up the formatting a little so we can see the code you are trying to run.&lt;/P&gt;
&lt;P&gt;So here is your macro definition. I removed the PROC FORMAT so it is not re-created everytime you call the macro. Also removed the empty data step.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%macro date(startyr, startmth,endyr,endmth);
libname pl&amp;amp;yymm. "\\kaiwksgh415thw5\Data\POLA\Claim\&amp;amp;endyr\&amp;amp;yymm\DBF";

%if &amp;amp;startmth=12 %then %do;
  %let accyr_fy1=%eval(&amp;amp;startyr+1);
  %let accmth_fy1=1;
%end;
%else %do;
  %let accyr_fy1=&amp;amp;startyr;
  %let accmth_fy1=%eval(&amp;amp;startmth+1);
%end;
%if &amp;amp;endmth=12 %then %do;
  %let accyr_fy2=%eval(&amp;amp;endyr+1);
  %let accmth_fy2=1;
%end;
%else %do;
  %let accyr_fy2=&amp;amp;endyr;
  %let accmth_fy2=%eval(&amp;amp;endmth+1);
%end;

%let accyrmth_fy1=%eval(&amp;amp;accyr_fy1*100+&amp;amp;accmth_fy1);
%let accyrmth_fy2=%eval(&amp;amp;accyr_fy2*100+&amp;amp;accmth_fy2);

PROC SQL;
create table SMCD_OS_&amp;amp;yymm. AS
  SELECT put(zmajrsk,$class.) as class
       , min(&amp;amp;accyrfy.-lossyr_fy,11) as dev11yr
       , accyr_fy
       , accmth_fy
       , sum(zclmos) AS zclmos
  FROM pl&amp;amp;yymm..POLA_clm_agg_&amp;amp;yymm.
  where (accyr_fy*100+accmth_fy)&amp;lt;=(&amp;amp;accyrfy.*100+&amp;amp;ACCMTHFY.)
  GROUP BY class,2,3,4
  order by accyr_fy,accmth_fy
;
quit;

ods html
  file="\\kaiwksgh415thw5\Data\POLA\Claim\&amp;amp;endyr\&amp;amp;yymm\result\SMCD_mth_OS_FY_10DY_&amp;amp;yymm..html"
  style=normal
;

proc print;
run;

%mend date;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Why do you not close the ODS HTML destination after the PROC PRINT?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Once you have defined your macro then your code is like this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let startyr=2015;
%let startmth=6;
%let endyr=2019;
%let endmth=2;
%let yymm=%eval(&amp;amp;endyr*100+&amp;amp;endmth);

proc format;
  value $ class
    'VEH'='1'
    'FIR'='2'
    'GMS'='3'
    'BON'='3'
    'HUL'='3'
    'PAC'='4'
    'TEL'='5'
    'WWC'='5'
    'LIA'='6'
    'CGO'='7'
    'ENG'='8'
  ;
run;

%date(&amp;amp;startyr, &amp;amp;startmth,&amp;amp;endyr,&amp;amp;endmth);&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Can you explain what it is that you want to loop?&lt;/P&gt;
&lt;P&gt;Do you want to call the macro multiple times?&lt;/P&gt;
&lt;P&gt;What changes between the calls?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Do you want the start year and start month to go from 2015-06 to 2019-02?&lt;/P&gt;
&lt;P&gt;Do you want the end year and end month to stay the same?&amp;nbsp; Do you want them to change also?&lt;/P&gt;
&lt;P&gt;How large are the datasets created by the SQL query and printed?&amp;nbsp; Are they 100 observations? 10 Million?&lt;/P&gt;
&lt;P&gt;Couldn't just just structure the SQL to generate all of the various sums of ZCLMOS in one query by joining with a table of yr/month values?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 02 Jul 2019 03:42:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/How-to-do-loop-from-one-date-to-another-date/m-p/570422#M160841</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-07-02T03:42:59Z</dc:date>
    </item>
  </channel>
</rss>

