<?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: Keep only most recent records in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441501#M110464</link>
    <description>&lt;P&gt;What most forum members would appreciate is if you could post sample data in the form of a working SAS data step so we don't have to do the work for you.&lt;/P&gt;
&lt;P&gt;It's not clear to me what constitutes the most recent exam. Below code sample assumes you're just after all the rows per ID with the latest year.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm=' ' truncover;
  input ID $ Calendar_Year Diagnosis $60.;
  datalines;
1 2016  TB 
1 2016 No health condition 
1 2016 No health condition 
2 2014 TB 
2 2016 Inactive/Latent Tuberculosis 
3 2014 TB 
3 2016 Inactive/Latent Tuberculosis 
3 2016 HIV 
3 2016 Hypertension 
4 2015 Cancer 
4 2014 No health condition 
4 2016 TB 
;
run;

proc sql;
  create table want as
    select *
    from have
    group by id
    having Calendar_Year=max(Calendar_Year)
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 02 Mar 2018 09:01:47 GMT</pubDate>
    <dc:creator>Patrick</dc:creator>
    <dc:date>2018-03-02T09:01:47Z</dc:date>
    <item>
      <title>Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441453#M110448</link>
      <description>&lt;P&gt;Hi everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a data with Diagnoses at each year of Medical exam. I am trying to select&amp;nbsp;ALL Diagnosis data (all lines) from the MOST RECENT EXAM ONLY, for each ID.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please, can you help me with the coding, see below the database structure.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&amp;nbsp;ID&lt;/TD&gt;&lt;TD&gt;Calendar Year&lt;/TD&gt;&lt;TD&gt;Diagnosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;&amp;nbsp;TB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;No health condition&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;1&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;No health condition&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;TB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;Inactive/Latent Tuberculosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;TB&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;Inactive/Latent Tuberculosis&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;HIV&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;Hypertension&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2015&lt;/TD&gt;&lt;TD&gt;Cancer&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2014&lt;/TD&gt;&lt;TD&gt;No health condition&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;2016&lt;/TD&gt;&lt;TD&gt;TB&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 03:46:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441453#M110448</guid>
      <dc:creator>seltonsy</dc:creator>
      <dc:date>2018-03-02T03:46:44Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441456#M110450</link>
      <description>&lt;P&gt;how the output&amp;nbsp; should look like.&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 04:32:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441456#M110450</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-03-02T04:32:53Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441464#M110456</link>
      <description>It doesn't matter much. If you have more than one way in your mind feel free to share. Well appreciated..&lt;BR /&gt;Thanks.</description>
      <pubDate>Fri, 02 Mar 2018 05:25:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441464#M110456</guid>
      <dc:creator>seltonsy</dc:creator>
      <dc:date>2018-03-02T05:25:01Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441501#M110464</link>
      <description>&lt;P&gt;What most forum members would appreciate is if you could post sample data in the form of a working SAS data step so we don't have to do the work for you.&lt;/P&gt;
&lt;P&gt;It's not clear to me what constitutes the most recent exam. Below code sample assumes you're just after all the rows per ID with the latest year.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dlm=' ' truncover;
  input ID $ Calendar_Year Diagnosis $60.;
  datalines;
1 2016  TB 
1 2016 No health condition 
1 2016 No health condition 
2 2014 TB 
2 2016 Inactive/Latent Tuberculosis 
3 2014 TB 
3 2016 Inactive/Latent Tuberculosis 
3 2016 HIV 
3 2016 Hypertension 
4 2015 Cancer 
4 2014 No health condition 
4 2016 TB 
;
run;

proc sql;
  create table want as
    select *
    from have
    group by id
    having Calendar_Year=max(Calendar_Year)
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:01:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441501#M110464</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2018-03-02T09:01:47Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441505#M110465</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*The Code will look like this*/
proc sort data=have;
by ID Calendar_Year;
run;

data want;
set have;
by ID Calendar_Year;
if last.ID then output;
run;

/*But if you have a Diagnoses_Date then It would be Perfect*/
proc sort data=have;
by ID Diagnoses_Date;
run;

data want;
set have;
by ID Diagnoses_Date;
if last.ID then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Mar 2018 09:07:52 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441505#M110465</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-02T09:07:52Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441559#M110490</link>
      <description>Thanks for the effort,&lt;BR /&gt;&lt;BR /&gt;I wanted to have not only the last line but all lines that have the latest exam date&lt;BR /&gt;&lt;BR /&gt;for example, you go to the doctor and he writes each diagnosis on a separate line with the same date for all exam&lt;BR /&gt;thanks</description>
      <pubDate>Fri, 02 Mar 2018 13:15:51 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441559#M110490</guid>
      <dc:creator>seltonsy</dc:creator>
      <dc:date>2018-03-02T13:15:51Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441563#M110491</link>
      <description>&lt;P&gt;How 'bout&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select *
from have
group by id
having diag_date = max(diag_date);
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Mar 2018 13:40:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441563#M110491</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2018-03-02T13:40:26Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441568#M110493</link>
      <description>&lt;P&gt;In That Case:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Using Solution provide by&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/11562"&gt;@Kurt_Bremser&lt;/a&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sql;
create table want as
select a.* from have a ,
(select id,diag_date
from have
group by id
having diag_date = max(diag_date))
where a.id=b.id and a.diag_date=b.diag_date
;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 02 Mar 2018 14:13:08 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/441568#M110493</guid>
      <dc:creator>Satish_Parida</dc:creator>
      <dc:date>2018-03-02T14:13:08Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only most recent records</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/442033#M110573</link>
      <description>&lt;P&gt;answer is important but asking question is even more important. it makes you successful. if you want to be successful it is very very important to ask question correctly and in effective manner, where in no one have to guess. Most of work in field depends on how to ask proper questions in business or in any other field&lt;/P&gt;</description>
      <pubDate>Sat, 03 Mar 2018 06:25:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Keep-only-most-recent-records/m-p/442033#M110573</guid>
      <dc:creator>kiranv_</dc:creator>
      <dc:date>2018-03-03T06:25:03Z</dc:date>
    </item>
  </channel>
</rss>

