<?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: Month-Year Loop in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290698#M60173</link>
    <description>&lt;P&gt;How about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year = 2011 + ceil(month/12);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to put them together:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;month_year = put(month, z2.) || '-' || put(year, 4.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added the leading zero for months, so they will sort properly and line up properly when printing.&lt;/P&gt;</description>
    <pubDate>Wed, 10 Aug 2016 12:49:12 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2016-08-10T12:49:12Z</dc:date>
    <item>
      <title>Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290680#M60165</link>
      <description>&lt;P&gt;I have the following dataset:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Month&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;6&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;8&lt;/P&gt;
&lt;P&gt;9&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;11&lt;/P&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;till 48.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to create a variable which appends 2012 from 1 to 12, then 2013 for 12-24 and 2014 from 24-48 and so on as follows. How to do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;month-year&lt;/P&gt;
&lt;P&gt;1-2012&lt;/P&gt;
&lt;P&gt;...&lt;/P&gt;
&lt;P&gt;12-2012&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1-2013&lt;/P&gt;
&lt;P&gt;....&lt;/P&gt;
&lt;P&gt;12-2013&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:04:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290680#M60165</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-10T12:04:25Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290684#M60166</link>
      <description>&lt;P&gt;I would recommend a SAS date.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Do year=2013 to 2016;
Do month=1 to 12;
Date=mdy(month, 1, year);
Output;
End;
End;

Format date monyy7.;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:20:55 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290684#M60166</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2016-08-10T12:20:55Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290686#M60167</link>
      <description>&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this, but I am getting 2304 observation when in fact I should only get 48.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:27:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290686#M60167</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-10T12:27:13Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290690#M60168</link>
      <description>&lt;P&gt;data have;&lt;BR /&gt;do m = 1 to 48;&lt;BR /&gt;output;&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;&lt;BR /&gt;if 1 &amp;lt;= _N_ &amp;lt;= 12 then new = catx('-',m,'2012');&lt;BR /&gt;else if 13 &amp;lt;= _N_ &amp;lt;= 24 then new = catx('-',m-12,'2013');&lt;BR /&gt;else if 25 &amp;lt;= _N_ &amp;lt;= 36 then new = catx('-',m-24,'2014');&lt;BR /&gt;else if 37 &amp;lt;= _N_ &amp;lt;= 48 then new = catx('-',m-36,'2015');&lt;BR /&gt;run;&lt;BR /&gt;proc print data = want(obs=30);&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:29:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290690#M60168</guid>
      <dc:creator>KachiM</dc:creator>
      <dc:date>2016-08-10T12:29:15Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290692#M60169</link>
      <description>&lt;P&gt;Your doing that logic for each row in your original dataset then aren't you. &amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;'s post showed you how to get your output without needing that other data. &amp;nbsp;I would also agree, use a date structure where dates are needed. &amp;nbsp;Also, why do you want a big long list on month-year data?&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:32:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290692#M60169</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-08-10T12:32:36Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290694#M60170</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/27005"&gt;@sasmaverick&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi Reeza,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I tried this, but I am getting 2304 observation when in fact I should only get 48.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Then you must have made a mistake when you copied the code. &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza&lt;/a&gt;'s code cannot have more than 48 iterations of the inner loop.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:37:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290694#M60170</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-10T12:37:31Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290695#M60171</link>
      <description>&lt;P&gt;What I am saying is I have only month data in the dataset (1-48). For the first 12 months, I want the date variable as 1-2012, 2-2012 till 12-2012. For the next 12, I need date as 1-2013, 2-2013 and so on.... I dont want the date as 48-2015, Instead I want it as 12-2015&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:40:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290695#M60171</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-10T12:40:38Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290697#M60172</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13879"&gt;@Reeza﻿&lt;/a&gt;'s code does not need that simple dataset 1 to 48 at all. Instead it creates the list of months on its own.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:44:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290697#M60172</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2016-08-10T12:44:45Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290698#M60173</link>
      <description>&lt;P&gt;How about:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;year = 2011 + ceil(month/12);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If you want to put them together:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;month_year = put(month, z2.) || '-' || put(year, 4.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I added the leading zero for months, so they will sort properly and line up properly when printing.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 12:49:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290698#M60173</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-10T12:49:12Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290741#M60193</link>
      <description>&lt;P&gt;The question I am asking is I have the following dataset:&lt;/P&gt;
&lt;P&gt;Month&lt;/P&gt;
&lt;P&gt;1&lt;/P&gt;
&lt;P&gt;2&lt;/P&gt;
&lt;P&gt;3&lt;/P&gt;
&lt;P&gt;4&lt;/P&gt;
&lt;P&gt;5&lt;/P&gt;
&lt;P&gt;6&lt;/P&gt;
&lt;P&gt;7&lt;/P&gt;
&lt;P&gt;8&lt;/P&gt;
&lt;P&gt;9&lt;/P&gt;
&lt;P&gt;10&lt;/P&gt;
&lt;P&gt;11&lt;/P&gt;
&lt;P&gt;12&lt;/P&gt;
&lt;P&gt;...till 48&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Expected Output as follows:&lt;/P&gt;
&lt;P&gt;Month Year&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1 &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2012&lt;/P&gt;
&lt;P&gt;2 &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;2012&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;3 &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;2012&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;4 &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;2012&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 15:33:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290741#M60193</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-10T15:33:13Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290749#M60197</link>
      <description>&lt;P&gt;Ah, yes.&amp;nbsp; Looks like we'll need a new variable as well:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;mon = mod(month, 12);&lt;/P&gt;
&lt;P&gt;if mon=0 then mon=1;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Then use MON instead of MONTH when constructing the combination variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;That's just one way ... there should be many ways to create MON.&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 15:49:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290749#M60197</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-08-10T15:49:24Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290750#M60198</link>
      <description>&lt;P&gt;How about&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
   set have;
   date = intnx('month','1Dec2011'd,month);
   format date mmyyD7.;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;The advantage with a date variable, which would be the first day of any given month, is that you can calculate a lot of things with date related functions and change display by use of formats without having to create new variables constantly.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 15:49:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290750#M60198</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2016-08-10T15:49:31Z</dc:date>
    </item>
    <item>
      <title>Re: Month-Year Loop</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290808#M60223</link>
      <description>&lt;P&gt;Yours alongwith Ballardw's suggestion helped me.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Wed, 10 Aug 2016 19:47:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Month-Year-Loop/m-p/290808#M60223</guid>
      <dc:creator>sasmaverick</dc:creator>
      <dc:date>2016-08-10T19:47:11Z</dc:date>
    </item>
  </channel>
</rss>

