<?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 How to select first obs based on sorting by several variables? in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393232#M11943</link>
    <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry to bother you for a question for selecting of first observation based on sorting by several variables. The dataset was sorted by ID, diagnosis and date of diagnosis. I would like to select the first observation with the first diagnosed date but the same diagnosis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use "first.ID and first.date" or "first.ID and first.date and first.diagnosis"but it seems not correct. I attached the test dataset. The records that I would like to select were highlighted in yellow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Sisi&lt;/P&gt;</description>
    <pubDate>Tue, 05 Sep 2017 14:24:37 GMT</pubDate>
    <dc:creator>Sisiwater</dc:creator>
    <dc:date>2017-09-05T14:24:37Z</dc:date>
    <item>
      <title>How to select first obs based on sorting by several variables?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393232#M11943</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Dear all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Sorry to bother you for a question for selecting of first observation based on sorting by several variables. The dataset was sorted by ID, diagnosis and date of diagnosis. I would like to select the first observation with the first diagnosed date but the same diagnosis.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried to use "first.ID and first.date" or "first.ID and first.date and first.diagnosis"but it seems not correct. I attached the test dataset. The records that I would like to select were highlighted in yellow.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Many thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Best&lt;/P&gt;&lt;P&gt;Sisi&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:24:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393232#M11943</guid>
      <dc:creator>Sisiwater</dc:creator>
      <dc:date>2017-09-05T14:24:37Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first obs based on sorting by several variables?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393235#M11944</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Sorry, I can't download Excel files, post test data as a datastep in the post.&lt;/P&gt;
&lt;P&gt;The principal should be sound, sort the data in the order you need, then last.&amp;lt;lowest of by group&amp;gt;.&lt;/P&gt;
&lt;P&gt;For example to get last date in each diagnosis:&lt;/P&gt;
&lt;PRE&gt;proc sort data=have;
  by id diagnosis date;
run;

data want;
  set have;
  by id diagnosis date;
  if last.diagnosis then output;
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:31:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393235#M11944</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2017-09-05T14:31:04Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first obs based on sorting by several variables?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393236#M11945</link>
      <description>&lt;P&gt;If you want the first time this DX appeared for this ID&amp;nbsp;then sort BY ID DX DATE and select the records where FIRST.DX is true.&lt;/P&gt;
&lt;P&gt;If you want the first DX for this ID then sort BY ID DATE and take FIRST.ID.&lt;/P&gt;</description>
      <pubDate>Tue, 05 Sep 2017 14:29:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/393236#M11945</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2017-09-05T14:29:16Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first obs based on sorting by several variables?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/395000#M12018</link>
      <description>&lt;P&gt;Thank you so much! I thought I replied through email but it seems not showed. Sorry about it! Thank you again!&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 06:29:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/395000#M12018</guid>
      <dc:creator>Sisiwater</dc:creator>
      <dc:date>2017-09-12T06:29:29Z</dc:date>
    </item>
    <item>
      <title>Re: How to select first obs based on sorting by several variables?</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/395120#M12025</link>
      <description>&lt;P&gt;I'm glad you found some useful info, &lt;A id="link_8" class="lia-link-navigation lia-page-link lia-user-name-link" href="https://communities.sas.com/t5/user/viewprofilepage/user-id/162857" target="_self"&gt;&lt;SPAN class=""&gt;Sisiwater&lt;/SPAN&gt;&lt;/A&gt;! If one of the replies was the exact solution to your problem, can you "Accept it as a solution"? Or if one was particularly helpful, feel free to "Like" it. This will help other community members who may run into the same issue know what worked.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;By the way, I deleted one of your replies that was duplicate. Maybe the first one&amp;nbsp;didn't come through right away when you replied via email.&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Thanks!&lt;BR /&gt;Anna&lt;/P&gt;</description>
      <pubDate>Tue, 12 Sep 2017 14:25:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/How-to-select-first-obs-based-on-sorting-by-several-variables/m-p/395120#M12025</guid>
      <dc:creator>AnnaBrown</dc:creator>
      <dc:date>2017-09-12T14:25:08Z</dc:date>
    </item>
  </channel>
</rss>

