<?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: Find out if a variable's value increase over time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454012#M284127</link>
    <description>&lt;P&gt;Answer for this depends on how your data looks like. Please provide some sample data. Here is a link for creating a sample data&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 13 Apr 2018 18:08:35 GMT</pubDate>
    <dc:creator>SuryaKiran</dc:creator>
    <dc:date>2018-04-13T18:08:35Z</dc:date>
    <item>
      <title>Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454009#M284126</link>
      <description>&lt;P&gt;I have a panel dataset of park area in 3000 different locations from 2000 to 2005. I want to find out which locations have an increase in park area after 2000. i.e., park_area2001 &amp;gt; park_area2000.&amp;nbsp;&lt;/P&gt;&lt;P&gt;If park_area2001&amp;gt;park_area2000, I want to assign values of park_area in 2001-2005 to be the same as park_area2000;&lt;/P&gt;&lt;P&gt;if park_area2001&amp;lt;park_area2000, then values of park_area in 2001-2005 are the same as value of park_area2001.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My dataset looks like:&lt;/P&gt;&lt;P&gt;year&amp;nbsp; &amp;nbsp; &amp;nbsp; location&amp;nbsp; &amp;nbsp; &amp;nbsp;park_area&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1000&lt;/P&gt;&lt;P&gt;2001&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1002&lt;/P&gt;&lt;P&gt;2002&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1010&lt;/P&gt;&lt;P&gt;2003&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1021&lt;/P&gt;&lt;P&gt;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1020&lt;/P&gt;&lt;P&gt;2005&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1020&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;990&lt;/P&gt;&lt;P&gt;2001&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;890&lt;/P&gt;&lt;P&gt;2002&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;890&lt;/P&gt;&lt;P&gt;2003&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;892&lt;/P&gt;&lt;P&gt;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;900&lt;/P&gt;&lt;P&gt;2005&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;905&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What are some ways for me to code this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you very much.&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:50:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454009#M284126</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-04-13T18:50:46Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454012#M284127</link>
      <description>&lt;P&gt;Answer for this depends on how your data looks like. Please provide some sample data. Here is a link for creating a sample data&amp;nbsp;&lt;A href="https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712" target="_blank"&gt;https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-data-AKA-generate/ta-p/258712&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 18:08:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454012#M284127</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-13T18:08:35Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454037#M284128</link>
      <description>&lt;P&gt;Check this out:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
infile datalines dlm=" ";
input year 4. location     park_area;
datalines;
2000 1 1000
2001 1 1002
2002 1 1010
2003 1 1021
2004 1 1020
2005 1 1020
2000 2 990
2001 2 890
2002 2 890
2003 2 892
2004 2 900
2005 2 905
;
run;
proc sort data=have;
by location year ;

data want(drop=lag);
retain park_area;
set have(rename=(park_area=area));
lag=lag(area);
if year=2000 then park_area=area;
if  year=2001 and area&amp;gt;lag then park_area=lag ;
if year=2001 and area&amp;lt;lag then park_area=area;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 19:25:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454037#M284128</guid>
      <dc:creator>SuryaKiran</dc:creator>
      <dc:date>2018-04-13T19:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454042#M284130</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
infile datalines dlm=" ";
input year 4. location     park_area;
datalines;
2000 1 1000
2001 1 1002
2002 1 1010
2003 1 1021
2004 1 1020
2005 1 1020
2000 2 990
2001 2 890
2002 2 890
2003 2 892
2004 2 900
2005 2 905
;
run;

data want;
set have;
by location year;
retain _p;
if first.location then call missing(_p);
if year=2000 then _p=park_area;
else do;
if year=2001 then _p=ifn(park_area&amp;gt;lag(park_area),_p,park_area);
if _p then park_area=_p;end;
drop _:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 13 Apr 2018 19:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454042#M284130</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-13T19:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454054#M284131</link>
      <description>&lt;P&gt;Thank you SuryaKiran!! Now I learned how to use lag. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 20:33:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454054#M284131</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-04-13T20:33:57Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454055#M284132</link>
      <description>&lt;P&gt;Thank you!!&lt;/P&gt;</description>
      <pubDate>Fri, 13 Apr 2018 20:34:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454055#M284132</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-04-13T20:34:39Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454087#M284133</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;SPAN class="login-bold"&gt;&lt;A href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205" target="_self"&gt;novinosrin&lt;/A&gt;, I am trying to replicate your code but I have some questions. What does "retain _p" do here? What does the underscore "_" do?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;I also have trouble to understand this line:&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;if first.location then call missing(_p)&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;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Apr 2018 00:02:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454087#M284133</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-04-14T00:02:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454092#M284134</link>
      <description>&lt;P&gt;_p is a flag or temp variable to hold the value from the previous record. _ is a fancy naming convention i am used to. Don't take much notice.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The call missing erases the held value of _p when sas processes a new by group to avoid any ambiguity. Hope that helps.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;PS I will prolly leave a nicer well explained notes tomorrow morning(Chicago time) when i get back to my college. I really do apologize for NOT so great explanation as I am racing against time to complete a personal assignment of mine that's due in tonight with just 2 hours to go. Hang in there. Cheers!&lt;/P&gt;</description>
      <pubDate>Sat, 14 Apr 2018 00:26:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454092#M284134</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-14T00:26:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454095#M284135</link>
      <description>&lt;P&gt;Thank you very much. The explanation you provided already helps a ton.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry for taking your time when you have things due that are much more important than this. Hope you get it finished in time!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 14 Apr 2018 00:44:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454095#M284135</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-04-14T00:44:13Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454150#M284136</link>
      <description>&lt;P&gt;Good morning, Here are the Notes:&lt;/P&gt;&lt;P&gt;1.&amp;nbsp;&lt;SPAN&gt;What does "retain _p" do here?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;SAS initializes all new variables created using an assignment statement to missing when it processes every record of a dataset. However we need to hold the value of year 2000 to look up when we process the record with year 2001. Therefore we use retain to override the default behavior to hold the record across observations.&lt;/P&gt;&lt;P&gt;2. Since we retained the value across observations, we need some or other way to let go of that value when we begin process a new by group set which in your case location happens to be the by group. So when SAS reads the first record of the new by group, the call missing overwrites the held value of _p from the previous by group assigning it with a missing value as mentioned earlier to avoid any ambiguity.&lt;/P&gt;&lt;P&gt;3. The flag variable is eventually dropped once our look up operation is complete at the end of the data-step.&lt;/P&gt;</description>
      <pubDate>Sat, 14 Apr 2018 15:29:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454150#M284136</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-04-14T15:29:56Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454159#M284137</link>
      <description>Thank you very much! Now I understand every step!</description>
      <pubDate>Sat, 14 Apr 2018 16:11:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/454159#M284137</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-04-14T16:11:52Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463466#M284138</link>
      <description>&lt;P&gt;Hi novinosrin&lt;SPAN class="login-bold"&gt;，sorry for bugging you again but I am running into a new problem.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;I realized that for some locations in my dataset, park_area values are only available for some of the years but not for all years within 2000-2005.&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Is there a way to revise the code so that&amp;nbsp;the values of park_area in&amp;nbsp;laters years are set equal to the first year that is available for that location (if values in later years are greater than the first year)?&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Here is the code I revised but it is not working:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;data have;&lt;BR /&gt;set want;&lt;BR /&gt;by&amp;nbsp;location year;&lt;BR /&gt;retain _p;&lt;BR /&gt;if first.location then call missing(_p);&lt;BR /&gt;if year=first.year then _p=park_area;&lt;BR /&gt;else do;&lt;BR /&gt;if year ne first.year then _p=ifn(park_area&amp;gt;lag(park_area), _p, park_area);&lt;BR /&gt;if _p then park_area=_p; end;&lt;BR /&gt;drop _:;&lt;/SPAN&gt;&lt;SPAN class="login-bold"&gt;&lt;BR /&gt;run;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN class="login-bold"&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 01:16:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463466#M284138</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-05-19T01:16:28Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463472#M284139</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74890"&gt;@Deester&lt;/a&gt;&amp;nbsp;Sure. Is it very urgent or can I give you the solution tomorrow chicago time at around 11am from my college lab?. If urgent i may have to sit just after supper. It's 9:10pm here in chicago right now.&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 02:11:24 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463472#M284139</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-19T02:11:24Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463473#M284140</link>
      <description>&lt;P&gt;Not urgent at all.&amp;nbsp; I actually just work it out myself, but I'd love to see how you approach it if you don't mind spending time on it.&lt;/P&gt;&lt;P&gt;What I did was:&lt;/P&gt;&lt;P&gt;1. I selected two top variables from each location group.&lt;/P&gt;&lt;P&gt;2. Created a flag variable indicating if the second observation is greater than the first observation.&lt;/P&gt;&lt;P&gt;3. Joining this new dataset with the original dataset and assigned values to later years.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you again!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 02:16:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463473#M284140</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-05-19T02:16:18Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463474#M284141</link>
      <description>&lt;P&gt;Absolutely no problem. Will respond to you in the morning without fail soon as I get to college. Enjoy your weekend and take care.&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 02:20:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463474#M284141</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-19T02:20:27Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463537#M284142</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/74890"&gt;@Deester&lt;/a&gt;&amp;nbsp;Good morning, Just to clarify a couple of points before I modify the code,&lt;/P&gt;&lt;P&gt;--&amp;gt;"I realized that for some locations in my dataset, park_area values are &lt;EM&gt;&lt;STRONG&gt;only available for some of the years but not for all years&lt;/STRONG&gt;&lt;/EM&gt;&amp;nbsp;within 2000-2005.&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My assumption:&lt;/STRONG&gt; This could mean the base year may not be year &lt;STRONG&gt;2000&lt;/STRONG&gt; and the code basically needs to check and pick the first available value as the base year in the sequence&amp;nbsp; and compare value with subsequent years? is my assumption right?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there a way to revise the code so that the values of park_area in later years are set equal to the first year that is available for that location (if &lt;EM&gt;&lt;STRONG&gt;values(in plural)&lt;/STRONG&gt;&lt;/EM&gt; in later years are greater than the first year)?"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;My assumption:&lt;/STRONG&gt; Can values increase or decrease, so for example, for year 2000 the value may be 250, then 280, then dropping to 240? This may not show a clear increasing trend&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If you have a few mins, can you modify your &lt;STRONG&gt;sample HAVE&lt;/STRONG&gt;&amp;nbsp; and show an expected &lt;STRONG&gt;OUTPUT(WANT)&lt;/STRONG&gt; &lt;STRONG&gt;sample&lt;/STRONG&gt;&amp;nbsp;covering the scenarios please?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 16:52:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463537#M284142</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-19T16:52:33Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463549#M284143</link>
      <description>&lt;P&gt;Good morning!!&lt;/P&gt;&lt;P&gt;To answer your questions:&lt;/P&gt;&lt;P&gt;1. Yes your assumption is correct.&lt;/P&gt;&lt;P&gt;2. I want to compare the first two values at each location. So the data looks like this:&lt;/P&gt;&lt;P&gt;My dataset looks like:&lt;/P&gt;&lt;P&gt;year&amp;nbsp; &amp;nbsp; &amp;nbsp; location&amp;nbsp; &amp;nbsp; &amp;nbsp;park_area&lt;/P&gt;&lt;P&gt;2001&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1002&lt;/P&gt;&lt;P&gt;2003&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1021&lt;/P&gt;&lt;P&gt;2004&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1020&lt;/P&gt;&lt;P&gt;2000&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;990&lt;/P&gt;&lt;P&gt;2002&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;890&lt;/P&gt;&lt;P&gt;2003&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;892&lt;/P&gt;&lt;P&gt;2005&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;905&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So for location 1, I want to compare 2001 (first available year) with 2003 (second available year). If park_area in 2001&amp;lt; park_area in 2003, then 2003 and 2004&amp;nbsp;park_area are set to be equal to the 2001 park_area value. If&amp;nbsp;&lt;SPAN&gt;park_area in 2001&amp;gt; park_area in 2003&lt;/SPAN&gt;, 2004 value is set to be equal to the 2003 value.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For location2, I want to compare 2000 and 2002. If park_area in 2000&amp;lt; park_area in 2002, then 2002, 2003, and 2005 park_area are set to be equal to the 2000 value.&amp;nbsp;&lt;SPAN&gt;If park_area in 2000&amp;gt; park_area in 2002, then 2003 and 2005 park_area are set to be equal to the 2002 value.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Hope this clarifies things.&amp;nbsp; Thank you!&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 17:27:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463549#M284143</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-05-19T17:27:12Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463551#M284144</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have ;
infile datalines dlm=" ";
input year 4. location     park_area;
datalines;
2001      1                  1002
2003      1                  1021
2004      1                  1020
2000      2                   990
2002      2                   890
2003      2                   892
2005      2                   905
;
run;
proc sort data= have out=_have;
by location year;
run;

data want;
set _have;
by location year;
retain _p;
if first.location then _p=park_area;
else _p=ifn(park_area&amp;gt;_p,_p,park_area);
if _p then park_area=_p;
drop _p;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 May 2018 17:40:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463551#M284144</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-19T17:40:32Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463552#M284145</link>
      <description>&lt;P&gt;Or a better bet:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
call missing(of __f,__p);
do _n_=1 by 1 until(last.location);
set _have;
by location year;
if _n_=1 then __p=park_area;
else if _n_=2 and not __f then do;
__p=ifn(park_area&amp;gt;__p,__p,park_area);
__f=1;
end;
if __p then  park_area=__p;
output;
end;
drop __:;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 19 May 2018 17:46:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463552#M284145</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-05-19T17:46:38Z</dc:date>
    </item>
    <item>
      <title>Re: Find out if a variable's value increase over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463557#M284146</link>
      <description>&lt;P&gt;Thank you!! The first code worked. It's very similar to the one I had but I made some small mistakes.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this didn't take too much of your time! I really appreciate your help!!&lt;/P&gt;</description>
      <pubDate>Sat, 19 May 2018 18:10:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Find-out-if-a-variable-s-value-increase-over-time/m-p/463557#M284146</guid>
      <dc:creator>Deester</dc:creator>
      <dc:date>2018-05-19T18:10:39Z</dc:date>
    </item>
  </channel>
</rss>

