<?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 Conditional grouping in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-grouping/m-p/61470#M17455</link>
    <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I currently have data that looks like this.&lt;BR /&gt;
&lt;BR /&gt;
NAME    OFFICE_ID    YEAR_QTR    END_TERM&lt;BR /&gt;
BILL          1                    20021            20024&lt;BR /&gt;
BILL          2                    20021            20022&lt;BR /&gt;
JOE          3                    20021             20033&lt;BR /&gt;
JOE          4                    20021            20031&lt;BR /&gt;
&lt;BR /&gt;
For each person, I would like to flag the Office_ID with the latest End_Term, so my data would look something like this&lt;BR /&gt;
&lt;BR /&gt;
NAME    OFFICE_ID    YEAR_QTR    END_TERM  FLAG&lt;BR /&gt;
BILL          1                    20021            20024         1&lt;BR /&gt;
BILL          2                    20021            20022          0&lt;BR /&gt;
JOE          3                    20021             20033         1&lt;BR /&gt;
JOE          4                    20021            20031          0&lt;BR /&gt;
&lt;BR /&gt;
I would like to achieve this using PROC SQL, but any tips are welcome.  Thank you very much.  I am using SAS 9.1.</description>
    <pubDate>Tue, 04 Aug 2009 19:55:22 GMT</pubDate>
    <dc:creator>deleted_user</dc:creator>
    <dc:date>2009-08-04T19:55:22Z</dc:date>
    <item>
      <title>Conditional grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-grouping/m-p/61470#M17455</link>
      <description>Hello,&lt;BR /&gt;
&lt;BR /&gt;
I currently have data that looks like this.&lt;BR /&gt;
&lt;BR /&gt;
NAME    OFFICE_ID    YEAR_QTR    END_TERM&lt;BR /&gt;
BILL          1                    20021            20024&lt;BR /&gt;
BILL          2                    20021            20022&lt;BR /&gt;
JOE          3                    20021             20033&lt;BR /&gt;
JOE          4                    20021            20031&lt;BR /&gt;
&lt;BR /&gt;
For each person, I would like to flag the Office_ID with the latest End_Term, so my data would look something like this&lt;BR /&gt;
&lt;BR /&gt;
NAME    OFFICE_ID    YEAR_QTR    END_TERM  FLAG&lt;BR /&gt;
BILL          1                    20021            20024         1&lt;BR /&gt;
BILL          2                    20021            20022          0&lt;BR /&gt;
JOE          3                    20021             20033         1&lt;BR /&gt;
JOE          4                    20021            20031          0&lt;BR /&gt;
&lt;BR /&gt;
I would like to achieve this using PROC SQL, but any tips are welcome.  Thank you very much.  I am using SAS 9.1.</description>
      <pubDate>Tue, 04 Aug 2009 19:55:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-grouping/m-p/61470#M17455</guid>
      <dc:creator>deleted_user</dc:creator>
      <dc:date>2009-08-04T19:55:22Z</dc:date>
    </item>
    <item>
      <title>Re: Conditional grouping</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Conditional-grouping/m-p/61471#M17456</link>
      <description>Generally speaking, SQL is a much poorer query and manipulation language than the sas language. In this case tho, I think you need 2 steps no matter what, so SQL is fine. This should do:&lt;BR /&gt;
&lt;BR /&gt;
   select a.*, a.OFFICE_ID=b.OFFICE_ID as FLAG &lt;BR /&gt;
   from TEST a, &lt;BR /&gt;
        (select NAME, OFFICE_ID &lt;BR /&gt;
         from TEST &lt;BR /&gt;
         group by NAME&lt;BR /&gt;
         having END_TERM=max(END_TERM)) b &lt;BR /&gt;
   where a.NAME=b.NAME;</description>
      <pubDate>Tue, 04 Aug 2009 23:08:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Conditional-grouping/m-p/61471#M17456</guid>
      <dc:creator>ChrisNZ</dc:creator>
      <dc:date>2009-08-04T23:08:19Z</dc:date>
    </item>
  </channel>
</rss>

