<?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: Dealing with close change in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446386#M283234</link>
    <description>&lt;P&gt;And here another solution option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data source;
  input Firm Year Change Solved;
  datalines;
1001 2000 0 0
1001 2001 0 0
1001 2002 1 0
1001 2003 0 0
1001 2004 1 1
1001 2005 0 0
1001 2006 0 0
1002 2002 0 0
1002 2003 1 0
1002 2004 1 0
1002 2005 1 1
1002 2006 0 0
1002 2007 0 0
1003 1999 0 0
1003 2000 1 1
1003 2001 0 0
1003 2002 0 0
1003 2003 0 0
1003 2004 1 1
1003 2005 0 0
;
run;

data target(drop=_:);

  if _n_=1 then
    do;
      dcl hash h1(dataset:'source (where=(change=1))');
      h1.defineKey('firm','year');
      h1.defineDone();
    end;

  set source;

  solved2=change;
  if change=1 then
    do _year=year+1 to year+3;
      if h1.check(key:firm, key:_year)=0 then
        do;
          solved2=0;
          leave;
        end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 16 Mar 2018 23:39:05 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2018-03-16T23:39:05Z</dc:date>
    <item>
      <title>Dealing with close change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446333#M283231</link>
      <description>&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want to change a certain&amp;nbsp;value&amp;nbsp;of prior period that is very close to one of the following periods.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For example,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data want;&lt;/P&gt;&lt;P&gt;input&amp;nbsp;Firm Year Change Solved;&lt;/P&gt;&lt;P&gt;datalines;&lt;/P&gt;&lt;P&gt;1001 2000 0 0&lt;/P&gt;&lt;P&gt;1001 2001 0 0&lt;/P&gt;&lt;P&gt;1001 2002 1 0&lt;/P&gt;&lt;P&gt;1001 2003 0 0&lt;/P&gt;&lt;P&gt;1001 2004 1 1&lt;/P&gt;&lt;P&gt;1001 2005 0 0&lt;/P&gt;&lt;P&gt;1001 2006 0 0&lt;/P&gt;&lt;P&gt;1002 2002 0 0&lt;/P&gt;&lt;P&gt;1002 2003 1 0&lt;/P&gt;&lt;P&gt;1002 2004 1 0&lt;/P&gt;&lt;P&gt;1002 2005 1 1&lt;/P&gt;&lt;P&gt;1002 2006 0 0&lt;/P&gt;&lt;P&gt;1002 2007 0 0&lt;/P&gt;&lt;P&gt;1003 1999 0 0&lt;/P&gt;&lt;P&gt;1003 2000 1 1&lt;/P&gt;&lt;P&gt;1003 2001 0 0&lt;/P&gt;&lt;P&gt;1003 2002 0 0&lt;/P&gt;&lt;P&gt;1003 2003 0 0&lt;/P&gt;&lt;P&gt;1003 2004 1 1&lt;/P&gt;&lt;P&gt;1003 2005 0 0&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The solved column is what I want to have in my dataset.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If a firm has a change = 1 in very close period (within 3 years) with the next period when change = 1, I want to make the former change = 1 to 0. That is, I want to have at least 3 years gap between changes by firms.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please help me this problem.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:15:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446333#M283231</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-16T20:15:09Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with close change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446345#M283232</link>
      <description>&lt;P&gt;I'm not sure if I understood your requirement or not. Also wondering how did you get the highlighted result, since the years are not &amp;gt;=3 years. I made a solution depending on my understanding on your requirement.&lt;/P&gt;
&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/198000"&gt;@hkim3677&lt;/a&gt; wrote:&lt;BR /&gt;
&lt;P&gt;Hi,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I want to change a certain&amp;nbsp;value&amp;nbsp;of prior period that is very close to one of the following periods.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Data want;&lt;/P&gt;
&lt;P&gt;input&amp;nbsp;Firm Year Change Solved;&lt;/P&gt;
&lt;P&gt;datalines;&lt;/P&gt;
&lt;P&gt;1001 2000 0 0&lt;/P&gt;
&lt;P&gt;1001 2001 0 0&lt;/P&gt;
&lt;P&gt;1001 2002 1 0&lt;/P&gt;
&lt;P&gt;1001 2003 0 0&lt;/P&gt;
&lt;P&gt;1001 2004 1 1&lt;/P&gt;
&lt;P&gt;1001 2005 0 0&lt;/P&gt;
&lt;P&gt;1001 2006 0 0&lt;/P&gt;
&lt;P&gt;1002 2002 0 0&lt;/P&gt;
&lt;P&gt;1002 2003 1 0&lt;/P&gt;
&lt;P&gt;1002 2004 1 0&lt;/P&gt;
&lt;P&gt;1002 2005 1 1&lt;/P&gt;
&lt;P&gt;1002 2006 0 0&lt;/P&gt;
&lt;P&gt;1002 2007 0 0&lt;/P&gt;
&lt;P&gt;1003 1999 0 0&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;FONT size="4"&gt;1003 2000 1 1&lt;/FONT&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;1003 2001 0 0&lt;/P&gt;
&lt;P&gt;1003 2002 0 0&lt;/P&gt;
&lt;P&gt;1003 2003 0 0&lt;/P&gt;
&lt;P&gt;1003 2004 1 1&lt;/P&gt;
&lt;P&gt;1003 2005 0 0&lt;/P&gt;
&lt;P&gt;;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The solved column is what I want to have in my dataset.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If a firm has a change = 1 in very close period (within 3 years) with the next period when change = 1, I want to make the former change = 1 to 0. That is, I want to have at least 3 years gap between changes by firms.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please help me this problem.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you!&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt; Data have;
input Firm Year Change Solved;
datalines;
1001 2000 0 0
1001 2001 0 0
1001 2002 1 0
1001 2003 0 0
1001 2004 1 1
1001 2005 0 0
1001 2006 0 0
1002 2002 0 0
1002 2003 1 0
1002 2004 1 0
1002 2005 1 1
1002 2006 0 0
1002 2007 0 0
1003 1999 0 0
1003 2000 1 1
1003 2001 0 0
1003 2002 0 0
1003 2003 0 0
1003 2004 1 1
1003 2005 0 0
;
run;
proc sort data=have;
by firm year;
run;
DATA want(Drop=dif count);
retain count;
set have ;
by firm year;
dif=dif(year);
if first.firm then do;
			dif=0;
			count=dif;
			end;
else count=count+dif;
if change=1 and count&amp;lt;3 then new_solve=0;
else if change=1 and count&amp;gt;=3 then do;
						new_solve=1;
						count=dif;
						end;
else new_solve=change;
run;
 &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 20:50:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446345#M283232</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-03-16T20:50:56Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with close change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446348#M283233</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data have;

input Firm Year Change ;

datalines;
1001 2000 0 0
1001 2001 0 0
1001 2002 1 0
1001 2003 0 0
1001 2004 1 1
1001 2005 0 0
1001 2006 0 0
1002 2002 0 0
1002 2003 1 0
1002 2004 1 0
1002 2005 1 1
1002 2006 0 0
1002 2007 0 0
1003 1999 0 0
1003 2000 1 1
1003 2001 0 0
1003 2002 0 0
1003 2003 0 0
1003 2004 1 1
1003 2005 0 0
;

run;

data want;
do _n_=1 by 1 until(last.firm);
set have;
by firm;
array h(1000) _temporary_;/*arbitrary*/
if first.firm then call missing(of h(*));
if  _t and change and year-_t&amp;lt;=3 then h(_n_)=_t;
if Change then _t=year;
end;
do until(last.firm);
set have;
by firm;
if change and year not in h then solved=1;
else solved=0;
output;
drop  _t;
end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Mar 2018 21:07:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446348#M283233</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-03-16T21:07:16Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with close change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446386#M283234</link>
      <description>&lt;P&gt;And here another solution option:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data source;
  input Firm Year Change Solved;
  datalines;
1001 2000 0 0
1001 2001 0 0
1001 2002 1 0
1001 2003 0 0
1001 2004 1 1
1001 2005 0 0
1001 2006 0 0
1002 2002 0 0
1002 2003 1 0
1002 2004 1 0
1002 2005 1 1
1002 2006 0 0
1002 2007 0 0
1003 1999 0 0
1003 2000 1 1
1003 2001 0 0
1003 2002 0 0
1003 2003 0 0
1003 2004 1 1
1003 2005 0 0
;
run;

data target(drop=_:);

  if _n_=1 then
    do;
      dcl hash h1(dataset:'source (where=(change=1))');
      h1.defineKey('firm','year');
      h1.defineDone();
    end;

  set source;

  solved2=change;
  if change=1 then
    do _year=year+1 to year+3;
      if h1.check(key:firm, key:_year)=0 then
        do;
          solved2=0;
          leave;
        end;
    end;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 23:39:05 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446386#M283234</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-16T23:39:05Z</dc:date>
    </item>
    <item>
      <title>Re: Dealing with close change</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446390#M283235</link>
      <description>&lt;P&gt;All above solutions are working good!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you masters!&lt;/P&gt;</description>
      <pubDate>Fri, 16 Mar 2018 23:52:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Dealing-with-close-change/m-p/446390#M283235</guid>
      <dc:creator>hkim3677</dc:creator>
      <dc:date>2018-03-16T23:52:51Z</dc:date>
    </item>
  </channel>
</rss>

