<?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: Automatically flagging blocks of 6 months time period in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246447#M46109</link>
    <description>&lt;P&gt;Here is one solution, I'm sure there are many:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if month in ('01','02','03','04','11','12') then Period = 1;&lt;BR /&gt;else period = 2;&lt;BR /&gt;run;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Jan 2016 21:25:42 GMT</pubDate>
    <dc:creator>Steelers_In_DC</dc:creator>
    <dc:date>2016-01-27T21:25:42Z</dc:date>
    <item>
      <title>Automatically flagging blocks of 6 months time period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246434#M46101</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have the following data set (below), with variables Year, Month and Paid, and I would like to add the column Period.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The column Period should have three values:&lt;/P&gt;
&lt;P&gt;0 &amp;nbsp;- for months I'm not interested in,&lt;/P&gt;
&lt;P&gt;1 - &amp;nbsp;for the 1st 6 months block period, and&lt;/P&gt;
&lt;P&gt;2 &lt;SPAN&gt;- &amp;nbsp;for the 2nd&amp;nbsp;6 months block period starting at the last Year and Month combination&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;The reason I am creating this variable is that so I can do a rolling sum for Periods 1 and 2, so I can do percent changes between these two 6 months block time periods.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What I would like to do would be to have SAS&amp;nbsp;look at the LAST Year and Month&amp;nbsp;in the dataset, and flag records from the last date going&amp;nbsp;back 6 months as the 2nd period, and then have SAS flag the 1st&amp;nbsp;period (which would be right before the 2nd period). The variable Period is shown below for visuals.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;YEAR MONTH PAID PERIOD&lt;BR /&gt;2014 01 $5,484,836.87 &amp;nbsp; 0&lt;BR /&gt;2014 02 $5,229,032.74 &amp;nbsp; 0&lt;BR /&gt;2014 03 $5,528,373.34 &amp;nbsp; 0&lt;BR /&gt;2014 04 $5,855,910.75 &amp;nbsp; 0&lt;BR /&gt;2014 05 $5,769,180.17 &amp;nbsp; 0&lt;BR /&gt;2014 06 $5,605,305.96 &amp;nbsp; 0&lt;BR /&gt;2014 07 $5,800,910.48 &amp;nbsp; 0&lt;BR /&gt;2014 08 $5,965,676.99 &amp;nbsp; 0&lt;BR /&gt;2014 09 $6,051,208.88 &amp;nbsp; 0&lt;BR /&gt;2014 10 $6,959,524.85 &amp;nbsp; 0&lt;BR /&gt;2014 11 $5,732,182.10 &amp;nbsp; 1&lt;BR /&gt;2014 12 $6,536,995.80 &amp;nbsp; 1&lt;BR /&gt;2015 01 $5,458,022.75 &amp;nbsp; 1&lt;BR /&gt;2015 02 $5,603,222.14 &amp;nbsp; 1&lt;BR /&gt;2015 03 $6,266,351.95 &amp;nbsp; 1&lt;BR /&gt;2015 04 $6,216,757.90 &amp;nbsp; 1&lt;BR /&gt;2015 05 $5,856,030.17 &amp;nbsp; 2&lt;BR /&gt;2015 06 $6,534,000.39 &amp;nbsp; 2&lt;BR /&gt;2015 07 $5,780,824.61 &amp;nbsp; 2&lt;BR /&gt;2015 08 $5,858,441.51 &amp;nbsp; 2&lt;BR /&gt;2015 09 $5,672,399.61 &amp;nbsp; 2&lt;BR /&gt;2015 10 $5,857,949.56 &amp;nbsp; 2&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;But I am doing this manually this way:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;data paid;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; set paid;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;period = 0;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;/*UPDATE*/&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; if YEAR = "2015" and&amp;nbsp;MONTH ge "05" then period = 2;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;else if YEAR = "2015" and&amp;nbsp;MONTH le "04" then period = 1;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;else if YEAR = "2014" and MONTH in ("11","12") then period = 1;&lt;/EM&gt;&lt;BR /&gt;&lt;EM&gt;run;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;but would love an automated or more elegant solution, so I don't have to manually update these date ranges monthly to define these time periods.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know your ideas. Thank you!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 19:57:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246434#M46101</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2016-01-27T19:57:08Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically flagging blocks of 6 months time period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246447#M46109</link>
      <description>&lt;P&gt;Here is one solution, I'm sure there are many:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;if month in ('01','02','03','04','11','12') then Period = 1;&lt;BR /&gt;else period = 2;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Jan 2016 21:25:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246447#M46109</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-27T21:25:42Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically flagging blocks of 6 months time period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246677#M46178</link>
      <description>&lt;P&gt;HI &lt;SPAN class="login-bold"&gt;&lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/30712" target="_self"&gt;Steelers_In_DC&lt;/A&gt;,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;thanks for you reply. I should have added that the data set is never static.&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;So the last year and month combination on a sorted dataset could be anything. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;So what I am looking for is a more automated solution (maybe with macros?), where sas looks at the last&amp;nbsp;&lt;SPAN&gt;year and month &lt;/SPAN&gt;record in the dataset, and back flags two 6 months periods.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thanks for your help tho!&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 16:24:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246677#M46178</guid>
      <dc:creator>avbraga</dc:creator>
      <dc:date>2016-01-28T16:24:59Z</dc:date>
    </item>
    <item>
      <title>Re: Automatically flagging blocks of 6 months time period</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246740#M46213</link>
      <description>&lt;P&gt;I gotcha, I tried to do something a little fancier with a hash but I'm still a beginner with those.&amp;nbsp; Here is a solution based on the end of the file:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;data have;&lt;BR /&gt;infile cards;&lt;BR /&gt;informat YEAR $4. MONTH $2. PAID dollar13.2;&lt;BR /&gt;format year $4. month $2. paid dollar13.2;&lt;BR /&gt;input YEAR$ MONTH$ PAID;&lt;BR /&gt;cards;&lt;BR /&gt;2014 01 $5,484,836.87&lt;BR /&gt;2014 02 $5,229,032.74&lt;BR /&gt;2014 03 $5,528,373.34&lt;BR /&gt;2014 04 $5,855,910.75&lt;BR /&gt;2014 05 $5,769,180.17&lt;BR /&gt;2014 06 $5,605,305.96&lt;BR /&gt;2014 07 $5,800,910.48&lt;BR /&gt;2014 08 $5,965,676.99&lt;BR /&gt;2014 09 $6,051,208.88&lt;BR /&gt;2014 10 $6,959,524.85&lt;BR /&gt;2014 11 $5,732,182.10&lt;BR /&gt;2014 12 $6,536,995.80&lt;BR /&gt;2015 01 $5,458,022.75&lt;BR /&gt;2015 02 $5,603,222.14&lt;BR /&gt;2015 03 $6,266,351.95&lt;BR /&gt;2015 04 $6,216,757.90&lt;BR /&gt;2015 05 $5,856,030.17&lt;BR /&gt;2015 06 $6,534,000.39&lt;BR /&gt;2015 07 $5,780,824.61&lt;BR /&gt;2015 08 $5,858,441.51&lt;BR /&gt;2015 09 $5,672,399.61&lt;BR /&gt;2015 10 $5,857,949.56&lt;BR /&gt;;run;&lt;BR /&gt;&lt;BR /&gt;data date1;&lt;BR /&gt;format date min1 max1 min2 max2 yymmn6.;&lt;BR /&gt;set have end=eof;&lt;BR /&gt;by year;&lt;BR /&gt;date=intnx('month',input(cat(year,month),yymmn6.),0,'e');&lt;BR /&gt;if eof then do;&lt;BR /&gt;max2=date;&lt;BR /&gt;min2=intnx('month',date,-5,'e');&lt;BR /&gt;max1=intnx('month',date,-6,'e');&lt;BR /&gt;min1=intnx('month',date,-11,'e');&lt;BR /&gt;end;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;data date2(keep=min1 max1 min2 max2);&lt;BR /&gt;set date1 end=eof;&lt;BR /&gt;if eof;&lt;BR /&gt;run;&lt;BR /&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table prep as&lt;BR /&gt;select distinct a.date,a.year,a.month,a.paid,b.min1,b.max1,b.min2,b.max2&lt;BR /&gt;from date1 a left join&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; date2 b on&lt;BR /&gt;a.date &amp;gt;= b.min1&lt;BR /&gt;order by date;&lt;BR /&gt;&lt;BR /&gt;data want;&lt;BR /&gt;set prep;&lt;BR /&gt;Period = 0;&lt;BR /&gt;if min1 &amp;lt;= date &amp;lt;= max1 then Period = 1;&lt;BR /&gt;if min2 &amp;lt;= date &amp;lt;= max2 then Period = 2;&lt;BR /&gt;drop min: max: date;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Jan 2016 20:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Automatically-flagging-blocks-of-6-months-time-period/m-p/246740#M46213</guid>
      <dc:creator>Steelers_In_DC</dc:creator>
      <dc:date>2016-01-28T20:20:47Z</dc:date>
    </item>
  </channel>
</rss>

