<?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: Selecting limited observartions for each customer in SAS Enterprise Guide</title>
    <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-limited-observartions-for-each-customer/m-p/1522#M476</link>
    <description>I'm afraid this can't be done without opening a Code window and typing programming statements.&lt;BR /&gt;
For example :&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT DATA = yourDataSet OUT = work.sortedData ;&lt;BR /&gt;
   BY customerId &lt;BR /&gt;
      DESCENDING dateVariable ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
DATA yourFinalDataSet ;&lt;BR /&gt;
   SET work.sortedData ;&lt;BR /&gt;
   BY customerId ;&lt;BR /&gt;
   IF FIRST.customerId THEN nRows = 0 ; /* for a new customer, set nRows to 0 */&lt;BR /&gt;
   nRows + 1 ; /* increment nRows for each observation */&lt;BR /&gt;
   IF nRows &amp;lt;= 3 THEN OUTPUT ;&lt;BR /&gt;
/* only keep records when nRows &amp;lt; 4 */&lt;BR /&gt;
RUN ;</description>
    <pubDate>Fri, 13 Oct 2006 16:03:08 GMT</pubDate>
    <dc:creator>Olivier</dc:creator>
    <dc:date>2006-10-13T16:03:08Z</dc:date>
    <item>
      <title>Selecting limited observartions for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-limited-observartions-for-each-customer/m-p/1521#M475</link>
      <description>I have the case where in a particular table I have customers who might have more than one record (eg Orders).  I am wanting to do a query/data step on this table so that I can retrieve only the three most recent records.  The table has a timestamp (datetime format) variable that will allow me to sort by date, however I don't know how to limit it to only 3 records per customer.&lt;BR /&gt;
&lt;BR /&gt;
Any help would be greatly appreciated.&lt;BR /&gt;
&lt;BR /&gt;
DW</description>
      <pubDate>Mon, 09 Oct 2006 00:41:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-limited-observartions-for-each-customer/m-p/1521#M475</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2006-10-09T00:41:29Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting limited observartions for each customer</title>
      <link>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-limited-observartions-for-each-customer/m-p/1522#M476</link>
      <description>I'm afraid this can't be done without opening a Code window and typing programming statements.&lt;BR /&gt;
For example :&lt;BR /&gt;
&lt;BR /&gt;
PROC SORT DATA = yourDataSet OUT = work.sortedData ;&lt;BR /&gt;
   BY customerId &lt;BR /&gt;
      DESCENDING dateVariable ;&lt;BR /&gt;
RUN ;&lt;BR /&gt;
DATA yourFinalDataSet ;&lt;BR /&gt;
   SET work.sortedData ;&lt;BR /&gt;
   BY customerId ;&lt;BR /&gt;
   IF FIRST.customerId THEN nRows = 0 ; /* for a new customer, set nRows to 0 */&lt;BR /&gt;
   nRows + 1 ; /* increment nRows for each observation */&lt;BR /&gt;
   IF nRows &amp;lt;= 3 THEN OUTPUT ;&lt;BR /&gt;
/* only keep records when nRows &amp;lt; 4 */&lt;BR /&gt;
RUN ;</description>
      <pubDate>Fri, 13 Oct 2006 16:03:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Enterprise-Guide/Selecting-limited-observartions-for-each-customer/m-p/1522#M476</guid>
      <dc:creator>Olivier</dc:creator>
      <dc:date>2006-10-13T16:03:08Z</dc:date>
    </item>
  </channel>
</rss>

