<?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: removing consecutive returns less than X months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360633#M84951</link>
    <description>&lt;P&gt;This is exactly what I want.&lt;/P&gt;&lt;P&gt;Based on draycut's argument, this code completes the procedure&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!!! I really appreciate it!&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2017 06:16:13 GMT</pubDate>
    <dc:creator>jkim197</dc:creator>
    <dc:date>2017-05-23T06:16:13Z</dc:date>
    <item>
      <title>removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360620#M84941</link>
      <description>&lt;P&gt;Hello SAS programmers!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working with monthly stock data from Feb 1980 to Dec 2016.&lt;/P&gt;&lt;P&gt;The dataset has roughly 450,000 stock-month&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What I want to do is to create a variable which represents consecutive runs of months (within stocks and between stocks)&lt;/P&gt;&lt;P&gt;and remove all stock-month observations less than 6months runs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you check following data structure you'll catch this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;stock date run&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000JAN &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000FEB &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000MAR 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000APR &amp;nbsp;4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000AUG 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000SEP &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000DEC 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2001JAN &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2001FEB &amp;nbsp;3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000JAN &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000FEB &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000MAR &amp;nbsp;3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000APR &amp;nbsp;4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000AUG &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000SEP &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000DEC &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2001JAN &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2001FEB &amp;nbsp;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to fix my dataset as&amp;nbsp;following(Deleting stock-month block with maximum run&amp;lt;3).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;stock date run&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000JAN &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000FEB &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000MAR 3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000APR &amp;nbsp;4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000DEC 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2001JAN &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2001FEB &amp;nbsp;3&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2 2000JAN &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000FEB &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000MAR &amp;nbsp;3&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000APR &amp;nbsp;4&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2000DEC &amp;nbsp;1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2001JAN &amp;nbsp;2&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;2 2001FEB &amp;nbsp;3&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&gt;In this situation, how can I fix my dataset and variable "run"??&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Please notice that I have 450,000 obs of full dataset so please give me general approach to do this.&amp;nbsp;&lt;/P&gt;&lt;P&gt;THX.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 05:38:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360620#M84941</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2017-05-23T05:38:10Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360622#M84943</link>
      <description>&lt;P&gt;Is your date variable formatted in this way?&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 05:18:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360622#M84943</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-05-23T05:18:16Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360623#M84944</link>
      <description>&lt;P&gt;My dates are the last days of the month in given year,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;for example,&amp;nbsp;&lt;/P&gt;&lt;P&gt;30NOV1980&lt;/P&gt;&lt;P&gt;31DEC1980&lt;/P&gt;&lt;P&gt;31JAN1981&lt;/P&gt;&lt;P&gt;28FEB1981&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 05:25:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360623#M84944</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2017-05-23T05:25:02Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360624#M84945</link>
      <description>&lt;P&gt;Ok. Not sure I understand, eg these lines&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;1 2000OCT 1&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;1 2000SEP &amp;nbsp;2&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Why would your run variable increase in this case?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 05:32:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360624#M84945</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-05-23T05:32:09Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360625#M84946</link>
      <description>&lt;P&gt;Oh...sorry... TYPO..&lt;BR /&gt;it's August...I corrected it&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 05:39:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360625#M84946</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2017-05-23T05:39:03Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360626#M84947</link>
      <description>&lt;P&gt;Makes more sense. I have implemented your run variable, though I am not certain aboyut the restrictions to put on it. Here I simply output only if run &amp;lt; 3.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input stock$ date:date9.;
format date date9.;
datalines;
1 31JAN2000
1 28FEB2000
1 31MAR2000
1 30APR2000
1 31AUG2000
1 30SEP2000
1 31DEC2000
1 31JAN2001
1 28FEB2001
2 31JAN2000
2 28FEB2000
2 31MAR2000
2 30APR2000
2 31AUG2000
2 30SEP2000
2 31DEC2000
2 31JAN2001
2 28FEB2001
;

data want;
	set have;
	
	if intck('month',lag1(date),date) = 1 then run + 1;
	else run = 1;

	retain run 1;
	if run &amp;lt;3;			/* Subsetting if */
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 May 2017 05:46:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360626#M84947</guid>
      <dc:creator>PeterClemmensen</dc:creator>
      <dc:date>2017-05-23T05:46:49Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360629#M84948</link>
      <description>&lt;P&gt;If i understood your req:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; have;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by stock;&lt;/P&gt;&lt;P&gt;if first.stock then grp=&lt;STRONG&gt;0&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;if run=&lt;STRONG&gt;1&lt;/STRONG&gt; then grp+&lt;STRONG&gt;1&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;data&lt;/STRONG&gt; want;&lt;/P&gt;&lt;P&gt;do n=&lt;STRONG&gt;1&lt;/STRONG&gt; by &lt;STRONG&gt;1&lt;/STRONG&gt; until(last.grp);&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by stock grp;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;do until(last.grp);&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by stock grp;&lt;/P&gt;&lt;P&gt;if n&amp;gt;=&lt;STRONG&gt;3&lt;/STRONG&gt; then output;&lt;/P&gt;&lt;P&gt;end;&lt;/P&gt;&lt;P&gt;drop n grp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;run&lt;/STRONG&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;Naveen Srinivasan&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 05:58:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360629#M84948</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2017-05-23T05:58:53Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360633#M84951</link>
      <description>&lt;P&gt;This is exactly what I want.&lt;/P&gt;&lt;P&gt;Based on draycut's argument, this code completes the procedure&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much!!! I really appreciate it!&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 06:16:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360633#M84951</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2017-05-23T06:16:13Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360634#M84952</link>
      <description>This code for generating variable run is superb..&lt;BR /&gt;Thank you so much draycut for your advice.</description>
      <pubDate>Tue, 23 May 2017 06:17:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360634#M84952</guid>
      <dc:creator>jkim197</dc:creator>
      <dc:date>2017-05-23T06:17:28Z</dc:date>
    </item>
    <item>
      <title>Re: removing consecutive returns less than X months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360640#M84956</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
by stock;
retain count;
if first.stock then count=.;
if run=1 then count+1;
run;

data want2(where=(count2&amp;gt;=3));
do until(last.count);
set want;
by stock count;
retain count2;
if first.count then count2=1;
else count2+1;
end;
do until(last.count);
set want;
by stock count;
output;
end;
drop count count2;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 23 May 2017 07:13:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/removing-consecutive-returns-less-than-X-months/m-p/360640#M84956</guid>
      <dc:creator>Jagadishkatam</dc:creator>
      <dc:date>2017-05-23T07:13:22Z</dc:date>
    </item>
  </channel>
</rss>

