<?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 Using Rank to find the top nn values (1 in this case) in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536105#M73954</link>
    <description>&lt;P&gt;I have been unsuccessfully struggling with Rank to do what I think should be a simple task.&lt;/P&gt;&lt;P&gt;Essentially, I want to group a table (with many columns) by the first 2 columns and select all records where the group number for the second column=1.&lt;/P&gt;&lt;P&gt;Picture an auto service center database for a simplified example of what I'm trying to do:&lt;/P&gt;&lt;P&gt;The first&amp;nbsp;few columns are : Customer ID / Date of Service / Service Code / etc.&lt;/P&gt;&lt;P&gt;So I want all data for each customer regarding their&amp;nbsp;most recent date of service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The roadblock for me is that Rank produces the observation number instead of the position in the group, or subgroup, leaving me no way to select the most recent date of service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In practice, even if I set the 'LOW' option for ties, I can't check for Date-Of-Service-Rank = 1 because it's the low observation number, not the position in the group. So, if there were 99 records for the first customer, then&amp;nbsp;for the second customer all of the records I want might have Date-Of-Service-Rank=100.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I going about this the wrong way?&amp;nbsp; I hope my example makes sense.&lt;/P&gt;</description>
    <pubDate>Sat, 16 Feb 2019 01:34:45 GMT</pubDate>
    <dc:creator>JereNeal</dc:creator>
    <dc:date>2019-02-16T01:34:45Z</dc:date>
    <item>
      <title>Using Rank to find the top nn values (1 in this case)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536105#M73954</link>
      <description>&lt;P&gt;I have been unsuccessfully struggling with Rank to do what I think should be a simple task.&lt;/P&gt;&lt;P&gt;Essentially, I want to group a table (with many columns) by the first 2 columns and select all records where the group number for the second column=1.&lt;/P&gt;&lt;P&gt;Picture an auto service center database for a simplified example of what I'm trying to do:&lt;/P&gt;&lt;P&gt;The first&amp;nbsp;few columns are : Customer ID / Date of Service / Service Code / etc.&lt;/P&gt;&lt;P&gt;So I want all data for each customer regarding their&amp;nbsp;most recent date of service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The roadblock for me is that Rank produces the observation number instead of the position in the group, or subgroup, leaving me no way to select the most recent date of service.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In practice, even if I set the 'LOW' option for ties, I can't check for Date-Of-Service-Rank = 1 because it's the low observation number, not the position in the group. So, if there were 99 records for the first customer, then&amp;nbsp;for the second customer all of the records I want might have Date-Of-Service-Rank=100.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am I going about this the wrong way?&amp;nbsp; I hope my example makes sense.&lt;/P&gt;</description>
      <pubDate>Sat, 16 Feb 2019 01:34:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536105#M73954</guid>
      <dc:creator>JereNeal</dc:creator>
      <dc:date>2019-02-16T01:34:45Z</dc:date>
    </item>
    <item>
      <title>Re: Using Rank to find the top nn values (1 in this case)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536180#M73955</link>
      <description>Show what you tried please and we can tell you where you're going wrong.</description>
      <pubDate>Sat, 16 Feb 2019 18:21:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536180#M73955</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2019-02-16T18:21:43Z</dc:date>
    </item>
    <item>
      <title>Re: Using Rank to find the top nn values (1 in this case)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536195#M73956</link>
      <description>&lt;P&gt;Proc rank creates ranks for individual observations, not for groups or clusters of observations. If your data is sorted, you could get those ranks simply with:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have; by customerId dateOfService;
if first.customerId then rank=0;
if first.dateOfService then rank+1;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 16 Feb 2019 20:26:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536195#M73956</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2019-02-16T20:26:03Z</dc:date>
    </item>
    <item>
      <title>Re: Using Rank to find the top nn values (1 in this case)</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536811#M73989</link>
      <description>&lt;P&gt;Thank you PGStats and Reeza.&lt;/P&gt;&lt;P&gt;From PGStats' explanation, it looks like I was trying to use the Rank procedure for something it wasn't designed for.&lt;/P&gt;&lt;P&gt;Since I am trying to find the first item within each group, I will instead create a temporary table that only contains data from the first sub-group and then process that table instead.&lt;/P&gt;&lt;P&gt;Thank you for your fast responses.&amp;nbsp; Much appreciated.&lt;/P&gt;</description>
      <pubDate>Tue, 19 Feb 2019 16:30:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Using-Rank-to-find-the-top-nn-values-1-in-this-case/m-p/536811#M73989</guid>
      <dc:creator>JereNeal</dc:creator>
      <dc:date>2019-02-19T16:30:29Z</dc:date>
    </item>
  </channel>
</rss>

