<?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 Hierarchical data, keep specific observations only in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Hierarchical-data-keep-specific-observations-only/m-p/530484#M5752</link>
    <description>&lt;P&gt;This is a previously unanswered question, hoping someone can help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I have the following data let’s say with some duplicate injury dates. My goal is to keep the most severe of the duplicate injury dates along with the other unique injury records.&amp;nbsp;The hierarchy is as follows: Home(least severe)&amp;lt;Clinic&amp;lt;Hospital(more severe). So I would keep only the Clinic observation for ID 1, but for ID 2 I would keep the Clinic on the Feb 1st injury date (as it is more severe than Home for the same injury date) and the Feb 6th date since it’s another injury date and not a duplicate.&amp;nbsp;How do I code this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Injury date&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Location of injury&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Jan02,2007&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Home&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Jan02, 2007&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Clinic&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Feb01,2000&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Home&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Feb06,2000&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Hospital&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Feb01,2000&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Clinic&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
    <pubDate>Sun, 27 Jan 2019 16:19:44 GMT</pubDate>
    <dc:creator>learn2</dc:creator>
    <dc:date>2019-01-27T16:19:44Z</dc:date>
    <item>
      <title>Hierarchical data, keep specific observations only</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hierarchical-data-keep-specific-observations-only/m-p/530484#M5752</link>
      <description>&lt;P&gt;This is a previously unanswered question, hoping someone can help!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If I have the following data let’s say with some duplicate injury dates. My goal is to keep the most severe of the duplicate injury dates along with the other unique injury records.&amp;nbsp;The hierarchy is as follows: Home(least severe)&amp;lt;Clinic&amp;lt;Hospital(more severe). So I would keep only the Clinic observation for ID 1, but for ID 2 I would keep the Clinic on the Feb 1st injury date (as it is more severe than Home for the same injury date) and the Feb 6th date since it’s another injury date and not a duplicate.&amp;nbsp;How do I code this?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;ID&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Injury date&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Location of injury&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Jan02,2007&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Home&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;1&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Jan02, 2007&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Clinic&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Feb01,2000&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Home&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Feb06,2000&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Hospital&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;P&gt;2&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Feb01,2000&lt;/P&gt;&lt;/TD&gt;&lt;TD&gt;&lt;P&gt;Clinic&lt;/P&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Sun, 27 Jan 2019 16:19:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hierarchical-data-keep-specific-observations-only/m-p/530484#M5752</guid>
      <dc:creator>learn2</dc:creator>
      <dc:date>2019-01-27T16:19:44Z</dc:date>
    </item>
    <item>
      <title>Re: Hierarchical data, keep specific observations only</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Hierarchical-data-keep-specific-observations-only/m-p/530485#M5753</link>
      <description>&lt;P&gt;You are correct that the question has been asked before the solution below has changes that take into account your requirements for the date criteria.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data have;&lt;BR /&gt;input ID $ Injurydate:$20. Locationofinjury $;&lt;BR /&gt;infile cards dlm=' ';&lt;BR /&gt;cards;&lt;BR /&gt;1 Jan02,2007 Home &lt;BR /&gt;1 Jan02,2007 Clinic&lt;BR /&gt;2 Feb01,2000 Home&lt;BR /&gt;2 Feb06,2000 Hospital&lt;BR /&gt;2 Feb01,2000 Clinic&lt;BR /&gt;;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&lt;BR /&gt;data help;&lt;BR /&gt;set have;&lt;BR /&gt;if Locationofinjury="Home" then severity=1;&lt;BR /&gt;else if Locationofinjury="Clinic" then severity=2;&lt;BR /&gt;else if Locationofinjury="Hospital" then severity=3;&lt;BR /&gt;else severity=.;&lt;BR /&gt;run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;proc sort data=help;&lt;BR /&gt;by ID injurydate severity;&lt;BR /&gt;run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;data want(drop=severity);&lt;BR /&gt;set help;&lt;BR /&gt;by ID injurydate severity;&lt;BR /&gt;if last.injurydate;&lt;BR /&gt;run;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 27 Jan 2019 17:13:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Hierarchical-data-keep-specific-observations-only/m-p/530485#M5753</guid>
      <dc:creator>VDD</dc:creator>
      <dc:date>2019-01-27T17:13:06Z</dc:date>
    </item>
  </channel>
</rss>

