<?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: Using first and last function with ties in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89222#M18966</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you're truly trying to track team dates, then something like this might be better:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table team_dates as&lt;/P&gt;&lt;P&gt;select distinct team, game_date from have&lt;/P&gt;&lt;P&gt;order by team, game_date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set team_dates;&lt;/P&gt;&lt;P&gt;format game_lag 8.;&lt;/P&gt;&lt;P&gt;by team;&lt;/P&gt;&lt;P&gt;if first.team then game_lag=0;&lt;/P&gt;&lt;P&gt;else game_lag=game_date - lag(game_date);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;should produce something like&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Team&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Game_Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;game_lag&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/3/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/4/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4/6/12&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5/1/12&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/1/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/5/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 30 Jan 2013 20:00:16 GMT</pubDate>
    <dc:creator>DBailey</dc:creator>
    <dc:date>2013-01-30T20:00:16Z</dc:date>
    <item>
      <title>Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89208#M18952</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I want to be able to mark 3-4+ observations as the first based on them being tied on a date. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Data looks like this:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Player_ID&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Team&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Number&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/3/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;2&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/3/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;3&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/3/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;So I am trying to mark all of them as&amp;nbsp; 0 in the number column. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;If I do first.team, only the first would be 0, same with Date. Is there an easy solution to this? I am probably just missing it. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 04:43:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89208#M18952</guid>
      <dc:creator>Xamius32</dc:creator>
      <dc:date>2013-01-29T04:43:57Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89209#M18953</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;try the following code...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data = test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by team;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; set test;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; by team;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if first.team then do;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; retain number 0;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; end;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 06:12:02 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89209#M18953</guid>
      <dc:creator>UrvishShah</dc:creator>
      <dc:date>2013-01-29T06:12:02Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89210#M18954</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN&gt;Hi, i consume you are a tipster? please contact me on &lt;/SPAN&gt;&lt;A class="jive-link-email-small" href="mailto:stajer@usa.com"&gt;stajer@usa.com&lt;/A&gt;&lt;SPAN&gt; for bussines.&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 08:04:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89210#M18954</guid>
      <dc:creator>EdvinasS</dc:creator>
      <dc:date>2013-01-29T08:04:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89211#M18955</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;How would that take into account the dates? For each team, there are about 100 observations, and 2-3 that I want to mark as the first, if they all have the same first date.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 14:39:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89211#M18955</guid>
      <dc:creator>Xamius32</dc:creator>
      <dc:date>2013-01-29T14:39:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89212#M18956</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Try sort by date and team then first.team. Then the first occurence of each team within a given date gets selected.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 15:15:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89212#M18956</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-01-29T15:15:12Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89213#M18957</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Problem is I want to select all the observations for each time that are in the first date. Does that make sense? It seems first. can only select one observation for a particular group.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 15:48:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89213#M18957</guid>
      <dc:creator>Xamius32</dc:creator>
      <dc:date>2013-01-29T15:48:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89214#M18958</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yes it does, but&amp;nbsp; assuming you're grouping by something else you should be able to do it.&lt;/P&gt;&lt;P&gt;What does the following give you?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort data=have;&lt;/P&gt;&lt;P&gt;by team date player;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set have;&lt;/P&gt;&lt;P&gt;by team date;&lt;/P&gt;&lt;P&gt;retain number;&lt;/P&gt;&lt;P&gt;if first.team then number=0;&lt;/P&gt;&lt;P&gt;if first.date then number+1;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 16:20:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89214#M18958</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-01-29T16:20:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89215#M18959</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I see where you are going with it, and I am going to try a few things, but I probably should explain the back story.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I got the number variable as a way to see how many days it has been since a team has played, using the lag function. However, this of course didnt work fully as teams with multiple players on the same day would have a zero instead of a one. So I wanted to change all the zeroes to ones except for the first date for each team.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data gamedates4;&lt;/P&gt;&lt;P&gt;set gamedates2;&lt;/P&gt;&lt;P&gt;by team_name gamedate;&lt;/P&gt;&lt;P&gt;days=game_date-lag(game_date);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Im going to try what you said, but I need to figure out how to not mess up the rest of it.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 16:45:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89215#M18959</guid>
      <dc:creator>Xamius32</dc:creator>
      <dc:date>2013-01-29T16:45:37Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89216#M18960</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Looks like you need to include player_id in the sort and the by statement: by team date player_id;&lt;/P&gt;&lt;P&gt;then First.date refers to the first player's record within the date.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Also your Days calculation is probably incorrect as you are getting some days, the first days value for each team (except the first team) reflects the days between the last game of the previous team and the first of the current team.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;days=game_date-lag(game_date);&lt;/P&gt;&lt;P&gt;probably should have a:&lt;/P&gt;&lt;P&gt;if first.team then days=.; /* or what ever makes sense in your application*/&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 18:31:40 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89216#M18960</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2013-01-29T18:31:40Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89217#M18961</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Yea, I got rid of those by putting all negative values as zero.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Anyways, wouldn't the first.date still only capture the one players, I need to capture all the players with the first date for each team. I am starting to think I need to rethink this.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 20:21:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89217#M18961</guid>
      <dc:creator>Xamius32</dc:creator>
      <dc:date>2013-01-29T20:21:58Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89218#M18962</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;It will capture the first date and the retain will keep it at value until it changes again (another first.date) if you have BY variables in the proper sequence. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jan 2013 20:51:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89218#M18962</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-01-29T20:51:52Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89219#M18963</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;data need;&lt;/P&gt;&lt;P&gt;retain triger 0;&lt;/P&gt;&lt;P&gt;set original; by team date player_id;&lt;/P&gt;&lt;P&gt;if first.team = 1 then triger = 1; &lt;/P&gt;&lt;P&gt;if last.team = 1 then triger = 0;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;something like that?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;if you could give bigger dataset example and the outcome you want to achieve it would be much more easy to understand and explane. im working on something similar but i dont get your problem..&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2013 08:20:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89219#M18963</guid>
      <dc:creator>EdvinasS</dc:creator>
      <dc:date>2013-01-30T08:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89220#M18964</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Okay, last question. This worked, but one thing I realize is that the lag function will create zeroes on the teams that have multiple players on the same date (IE the dates are the same, so after the first, the lag is zero.) How can I tell it to retain days until the next gamedate? IE I put the days=game_date-lag(game_date), then I need to retain that value until the gamedate changes. MY thought was use if first.game_date=0 then days=lag(days). but it doesnt work.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2013 19:13:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89220#M18964</guid>
      <dc:creator>Xamius32</dc:creator>
      <dc:date>2013-01-30T19:13:41Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89221#M18965</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;why not retain days and only calculate it when the date changes and reset the lag at that point. &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2013 19:53:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89221#M18965</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2013-01-30T19:53:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using first and last function with ties</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89222#M18966</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you're truly trying to track team dates, then something like this might be better:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table team_dates as&lt;/P&gt;&lt;P&gt;select distinct team, game_date from have&lt;/P&gt;&lt;P&gt;order by team, game_date;&lt;/P&gt;&lt;P&gt;quit;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;/P&gt;&lt;P&gt;set team_dates;&lt;/P&gt;&lt;P&gt;format game_lag 8.;&lt;/P&gt;&lt;P&gt;by team;&lt;/P&gt;&lt;P&gt;if first.team then game_lag=0;&lt;/P&gt;&lt;P&gt;else game_lag=game_date - lag(game_date);&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;should produce something like&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Team&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;Game_Date&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;game_lag&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/3/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;A&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4/4/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;1&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;4/6/12&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;A&lt;/TD&gt;&lt;TD&gt;5/1/12&lt;/TD&gt;&lt;TD&gt;24&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/1/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;0&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;B&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;5/5/12&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;4&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 30 Jan 2013 20:00:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Using-first-and-last-function-with-ties/m-p/89222#M18966</guid>
      <dc:creator>DBailey</dc:creator>
      <dc:date>2013-01-30T20:00:16Z</dc:date>
    </item>
  </channel>
</rss>

