<?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: Modifying observation based on ID and test date in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360936#M10868</link>
    <description>&lt;P&gt;This is perfect. Thank you!!!&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 23 May 2017 21:42:47 GMT</pubDate>
    <dc:creator>mphqueens</dc:creator>
    <dc:date>2017-05-23T21:42:47Z</dc:date>
    <item>
      <title>Modifying observation based on ID and test date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360929#M10866</link>
      <description>&lt;P&gt;Hello! I am working on a dataset that contains patient ID numbers, biological sex (M, F, or U for unidentified), and a test date. I am looking to change all gender entries to the one on the most recent test date that corresponds with the patient ID. Some patients have been previously entered as U but have more recent entries that are M or F. However, in some cases there are both M and F entries associated with the ID but I want to assume the most recent test date is the correct gender. How can I code this?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to have the most possible Sex entries as M and F, with the most recent test date indicating the assumed truth. Some will have the most recent test date as U, therefore I would like to use the second most recent in those cases.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;An example:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Data addsex;&lt;BR /&gt;Input ID TESTDATE SEX;&lt;BR /&gt;datalines;&amp;nbsp;&lt;BR /&gt;1 2010/01/01 M&lt;/P&gt;&lt;P&gt;1 2012/02/07 F&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 2009/05/07 F&lt;/P&gt;&lt;P&gt;2 2012/06/09 U&amp;nbsp;&lt;/P&gt;&lt;P&gt;2 2007/12/12 F&lt;/P&gt;&lt;P&gt;3 2008/01/11 U&amp;nbsp;&lt;/P&gt;&lt;P&gt;3 2010/08/09 M&amp;nbsp;&lt;/P&gt;&lt;P&gt;4 2009/09/09 M&lt;/P&gt;&lt;P&gt;4 2012/09/03 M&amp;nbsp;&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 21:01:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360929#M10866</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2017-05-23T21:01:52Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying observation based on ID and test date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360931#M10867</link>
      <description>&lt;P&gt;This approach assumes that your data set is already in sorted order by ID and TESTDATE:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data want;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if sex in ('M', 'F') then most_recent = sex;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;do until (last.id);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; set have;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; by id;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; if most_recent in ('M', 'F') then sex = most_recent;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&amp;nbsp; output;&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;drop most_recent;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It might be overkill, but the program is careful to leave SEX unchanged when an ID has no values that are either 'M' or 'F'.&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 21:10:46 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360931#M10867</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2017-05-23T21:10:46Z</dc:date>
    </item>
    <item>
      <title>Re: Modifying observation based on ID and test date</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360936#M10868</link>
      <description>&lt;P&gt;This is perfect. Thank you!!!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 23 May 2017 21:42:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Modifying-observation-based-on-ID-and-test-date/m-p/360936#M10868</guid>
      <dc:creator>mphqueens</dc:creator>
      <dc:date>2017-05-23T21:42:47Z</dc:date>
    </item>
  </channel>
</rss>

