<?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: MAX with a conditional By group? in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327768#M62411</link>
    <description>&lt;P&gt;Well, something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have (rename=(year_l=tmp));
  retain year_l;
  if tmp ne "" then year_l=tmp;
run;&lt;/PRE&gt;
&lt;P&gt;Note, I &amp;nbsp;assume your data is character format as you have not posted the test data in a datastep.&lt;/P&gt;</description>
    <pubDate>Thu, 26 Jan 2017 17:09:15 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2017-01-26T17:09:15Z</dc:date>
    <item>
      <title>MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327766#M62410</link>
      <description>&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I ran into a problem where I have the following table:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Year &amp;nbsp;Year_L&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2000 2000&lt;BR /&gt;2001&lt;BR /&gt;2002&lt;BR /&gt;2003&lt;BR /&gt;2004 2004&lt;BR /&gt;2005&lt;BR /&gt;2006&lt;BR /&gt;2007&lt;BR /&gt;2008 2008&lt;BR /&gt;2009 2009&lt;BR /&gt;2010&lt;BR /&gt;2011&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and I want&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Year &amp;nbsp;Year_L&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2000 2000&lt;BR /&gt;2001 2000&lt;BR /&gt;2002 2000&lt;BR /&gt;2003 2000&lt;BR /&gt;2004 2004&lt;BR /&gt;2005 2004&lt;BR /&gt;2006 2004&lt;BR /&gt;2007 2004&lt;BR /&gt;2008 2008&lt;BR /&gt;2009 2009&lt;BR /&gt;2010 2009&lt;BR /&gt;2011 2009&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Basically I want all missing fields to take all previous latest Year_L.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note that I cannot use lags since data is too disorganized to have it sorted (and it's not quite in my control to make them more organized)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I thought about using max(Year_L) but I'm not sure how to set the "By GROUPS" so that it would take current year &amp;gt; year.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you so much!&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:02:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327766#M62410</guid>
      <dc:creator>chrischoi614</dc:creator>
      <dc:date>2017-01-26T17:02:18Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327768#M62411</link>
      <description>&lt;P&gt;Well, something like:&lt;/P&gt;
&lt;PRE&gt;data want;
  set have (rename=(year_l=tmp));
  retain year_l;
  if tmp ne "" then year_l=tmp;
run;&lt;/PRE&gt;
&lt;P&gt;Note, I &amp;nbsp;assume your data is character format as you have not posted the test data in a datastep.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:09:15 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327768#M62411</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-26T17:09:15Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327772#M62412</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;Thank you for your solution!&lt;BR /&gt;&lt;BR /&gt;I am wondering is there a way to make it work if its not in order? say if 2001 comes before the row of 2000.&lt;BR /&gt;&lt;BR /&gt;Thank you once again!</description>
      <pubDate>Thu, 26 Jan 2017 17:17:59 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327772#M62412</guid>
      <dc:creator>chrischoi614</dc:creator>
      <dc:date>2017-01-26T17:17:59Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327773#M62413</link>
      <description>&lt;P&gt;From your given example, you would sort by col1 then apply that code. &amp;nbsp;If there's no logically order, not sure how you could logically apply any condition. &amp;nbsp;Try posting test data in the form of a datastep which accurately describes your problem. &amp;nbsp;Follow this if you stuck:&lt;/P&gt;
&lt;P&gt;&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;Left for the day, will see responses tomorrow.&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:25:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327773#M62413</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-01-26T17:25:11Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327774#M62414</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/125624"&gt;@chrischoi614&lt;/a&gt; wrote:&lt;BR /&gt;&lt;BR /&gt;I am wondering is there a way to make it work if its not in order? say if 2001 comes before the row of 2000.&lt;BR /&gt;&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;If you have a more complex need you shoud provide example input, output and any actual rules for determining assignment.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For example I am not sure which variable&amp;nbsp;you mean to address that comes before 2000.&lt;/P&gt;
&lt;P&gt;It may be that the solution is to sort the data first and then apply the existing solution.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is the case you are thinking like this?&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Year &amp;nbsp;Year_L&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;2001&lt;/P&gt;
&lt;P&gt;2000 2000&lt;BR /&gt;2002&lt;BR /&gt;2003&lt;BR /&gt;2004 2004&lt;BR /&gt;2005&lt;BR /&gt;2006&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If so, what value should Year_L have and how do we know that it should get that value?&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:25:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327774#M62414</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-26T17:25:40Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327776#M62415</link>
      <description>The variables actually mean Year and Year of loss. IF there is a loss, Year_L will be populated with the same year.&lt;BR /&gt;&lt;BR /&gt;so since in 2000, there is a loss, in 2001, the latest loss up to 2001 is 2000. Therefore 2001 should have Year_L = 2000. Hope that explains the logic.&lt;BR /&gt;&lt;BR /&gt;Thank you so much!</description>
      <pubDate>Thu, 26 Jan 2017 17:35:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327776#M62415</guid>
      <dc:creator>chrischoi614</dc:creator>
      <dc:date>2017-01-26T17:35:02Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327782#M62416</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/125624"&gt;@chrischoi614&lt;/a&gt; wrote:&lt;BR /&gt;The variables actually mean Year and Year of loss. IF there is a loss, Year_L will be populated with the same year.&lt;BR /&gt;&lt;BR /&gt;so since in 2000, there is a loss, in 2001, the latest loss up to 2001 is 2000. Therefore 2001 should have Year_L = 2000. Hope that explains the logic.&lt;BR /&gt;&lt;BR /&gt;Thank you so much!&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;That really sounds like Sort the data and apply the previous solution should work.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 26 Jan 2017 17:41:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327782#M62416</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2017-01-26T17:41:19Z</dc:date>
    </item>
    <item>
      <title>Re: MAX with a conditional By group?</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327792#M62417</link>
      <description>Thank you! I will probably just do that.</description>
      <pubDate>Thu, 26 Jan 2017 17:59:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/MAX-with-a-conditional-By-group/m-p/327792#M62417</guid>
      <dc:creator>chrischoi614</dc:creator>
      <dc:date>2017-01-26T17:59:09Z</dc:date>
    </item>
  </channel>
</rss>

