<?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: Generating Reiterated Months and Years with Do Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568957#M160261</link>
    <description>&lt;P&gt;This is also a great solution.&amp;nbsp; I got it a few seconds too late to accept it as a solution, unfortunately.&amp;nbsp; (The SAS Users Community really should allow someone to accept more than one solution.)&amp;nbsp; Many thanks as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 26 Jun 2019 00:00:11 GMT</pubDate>
    <dc:creator>dbcrow</dc:creator>
    <dc:date>2019-06-26T00:00:11Z</dc:date>
    <item>
      <title>Generating Reiterated Months and Years with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568952#M160257</link>
      <description>&lt;P&gt;Hi, SAS Community-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This shouldn't be difficult, but I'm having a rough go of it.&amp;nbsp; I'm trying to generate a file in which each of the 58 California counties has 108 data points that are monthly increments (12) within years for nine (9) years of data, 2010-2018 (9 x 12 = 108).&amp;nbsp; The way I'm setting it up, the file has four columns:&amp;nbsp; county, date, year, and month.&amp;nbsp; So, for the first county, Alameda, we would have:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;County&amp;nbsp; &amp;nbsp; &amp;nbsp;Date&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Year&amp;nbsp; &amp;nbsp; &amp;nbsp;Month&lt;/P&gt;&lt;P&gt;Alameda&amp;nbsp; 01/01/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2010&amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;Alameda&amp;nbsp; 02/01/2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2010&amp;nbsp; &amp;nbsp; 2&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;Alameda&amp;nbsp; 12/01/2018&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2018&amp;nbsp; &amp;nbsp; 12&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The problem with the code that follows is that when I get to the end of the first county, Alameda, instead of the date counter starting over at 01/01/2010 in the next county (Alpine) the date continues.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want is this:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alpine&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2010&amp;nbsp; &amp;nbsp; &amp;nbsp;2010&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I get is this:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alpine&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01/01/2019&amp;nbsp; &amp;nbsp; &amp;nbsp;2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here's the code:&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;data template(keep=county yearmonth month year);
	retain county yearmonth month year;
	yearmonth = "01dec2009"d;
	do i = 1 to n;
		do year = 2010 to 2018;
			do month = 1 to 12;
				yearmonth = intnx("month",yearmonth,1); 
				set counties nobs=n point=i;
			output;
			end;
		end;
	end;
stop;
format yearmonth MMDDYYS.;
run;&lt;/PRE&gt;&lt;P&gt;Note that the data set "counties" is simply a list of the 58 counties.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any pointers would be greatly appreciated.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;David&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 23:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568952#M160257</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-06-25T23:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Reiterated Months and Years with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568953#M160258</link>
      <description>&lt;P&gt;Put the DO loop(s) after the SET statement.&amp;nbsp; So you read in one county and output multiple observations for that county.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;%let start='01JAN2010'd;
%let end='01DEC2018'd;
data template(keep=county yearmonth month year);
  set counties (keep=county);
  do i=0 to intck('month',&amp;amp;start,&amp;amp;end);
     yearmonth=intnx('month',&amp;amp;start,i);
     year=year(yearmonth);
     month=month(yearmonth);
    output;
  end;
  format yearmonth MMDDYYS10.;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 25 Jun 2019 23:45:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568953#M160258</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2019-06-25T23:45:50Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Reiterated Months and Years with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568954#M160259</link>
      <description>&lt;P&gt;An easy formula to replace the current one:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;yearmonth = mdy(month, 1, year);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It would be faster to execute the SET statement sequentially:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data template(keep=county yearmonth month year);
   set counties;
		do year = 2010 to 2018;
			do month = 1 to 12;
				yearmonth = mdy(month, 1, year);
			output;
			end;
		end;
	end;
stop;
format yearmonth MMDDYYS.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The order of the observations would change, however.&amp;nbsp; It's not clear which order would be best, but you can always sort the data.&lt;/P&gt;</description>
      <pubDate>Tue, 25 Jun 2019 23:51:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568954#M160259</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-06-25T23:51:39Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Reiterated Months and Years with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568955#M160260</link>
      <description>Many thanks! Worked like a charm.</description>
      <pubDate>Tue, 25 Jun 2019 23:55:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568955#M160260</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-06-25T23:55:56Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Reiterated Months and Years with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568957#M160261</link>
      <description>&lt;P&gt;This is also a great solution.&amp;nbsp; I got it a few seconds too late to accept it as a solution, unfortunately.&amp;nbsp; (The SAS Users Community really should allow someone to accept more than one solution.)&amp;nbsp; Many thanks as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 00:00:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/568957#M160261</guid>
      <dc:creator>dbcrow</dc:creator>
      <dc:date>2019-06-26T00:00:11Z</dc:date>
    </item>
    <item>
      <title>Re: Generating Reiterated Months and Years with Do Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/569135#M160340</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/241468"&gt;@dbcrow&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;This is also a great solution.&amp;nbsp; I got it a few seconds too late to accept it as a solution, unfortunately.&amp;nbsp; (The SAS Users Community really should allow someone to accept more than one solution.)&amp;nbsp; Many thanks as well.&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Don't worry about marking only a "first" solution as correct. The main thing is that a solution is indicated so that others searching for forum for similar issues can tell that particular question was solved somehow.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Depending on the specific problem there are often 3 or, some times many,&amp;nbsp;more "correct" solutions.&lt;/P&gt;</description>
      <pubDate>Wed, 26 Jun 2019 15:35:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Generating-Reiterated-Months-and-Years-with-Do-Loop/m-p/569135#M160340</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-06-26T15:35:46Z</dc:date>
    </item>
  </channel>
</rss>

