<?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: Extracting Data from Most Recent Record in SAS Procedures</title>
    <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104379#M29167</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you only want the final data set to contain the postal code for a chartno based on the last (most recent) admission date, then replace your last data step with this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by chartno;&lt;/P&gt;&lt;P&gt;retain last_postal;&lt;/P&gt;&lt;P&gt;if first.chartno then last_postal = postal;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 07 Aug 2013 20:54:30 GMT</pubDate>
    <dc:creator>Fugue</dc:creator>
    <dc:date>2013-08-07T20:54:30Z</dc:date>
    <item>
      <title>Extracting Data from Most Recent Record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104378#M29166</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I am using SAS 9.3.&amp;nbsp; I have a data set of all hospital visits for a single year by chart number (which is unique to the patient).&amp;nbsp; I want to report on the residence of each patient but I want the residence reported on to be from the most recent patient visit.&amp;nbsp; This is what I have so far:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;input @1&amp;nbsp; chartno $6.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @7&amp;nbsp; acctno&amp;nbsp; $3.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @10 admdate yymmdd8.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @18 sepdate yymmdd8.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; @26 postal $6.&lt;BR /&gt;&amp;nbsp;&amp;nbsp; ;&lt;/P&gt;&lt;P&gt;format admdate yymmdd10. sepdate yymmdd10.;&lt;/P&gt;&lt;P&gt;cards;&lt;BR /&gt;1111110012012032920120331N0H2C1&lt;BR /&gt;2222220022012050120120515L4M6X6&lt;BR /&gt;3333330032012060120120607L4N4A8&lt;BR /&gt;1111110042012040220120410N4L1H4&lt;BR /&gt;4444440052012060320120615N4L1S7&lt;BR /&gt;5555550062012053120120603L0L2K0&lt;BR /&gt;2222220072012070120120713L4M6X6&lt;BR /&gt;2222220082012072020120725L9Y2M7&lt;BR /&gt;4444440092012081320120817N4L1S7&lt;BR /&gt;3333330102012061520120621L4N4A8&lt;BR /&gt;1111110112012110120121130N4L1H4&lt;BR /&gt;run; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;proc sort in=have;&lt;BR /&gt;by chartno descending admdate;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want (drop=postal_lag);&lt;BR /&gt;set have;&lt;BR /&gt;by chartno;&lt;BR /&gt;format &lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; index_postal $6.&lt;BR /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ;&lt;BR /&gt;index_postal='';&lt;BR /&gt;postal_lag=lag(postal);&lt;BR /&gt;chart_lag=lag(chartno);&lt;/P&gt;&lt;P&gt;if first.chartno then index_postal=postal;&lt;BR /&gt;else index_postal=postal_lag;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The result is:&lt;/P&gt;&lt;P&gt;&lt;IMG alt="Results.jpg" class="jive-image-thumbnail jive-image" src="https://communities.sas.com/legacyfs/online/3983_Results.jpg" width="450" /&gt;&lt;/P&gt;&lt;P&gt;It seems to work for the occurrence after the first (i.e. chart 111111 and 222222) but not on the 3rd occurrence of 222222.&amp;nbsp; Any assistance is greatly appreciated.&amp;nbsp; Thanks.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 20:24:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104378#M29166</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2013-08-07T20:24:38Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Data from Most Recent Record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104379#M29167</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;If you only want the final data set to contain the postal code for a chartno based on the last (most recent) admission date, then replace your last data step with this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;data want;&lt;BR /&gt;set have;&lt;BR /&gt;by chartno;&lt;/P&gt;&lt;P&gt;retain last_postal;&lt;/P&gt;&lt;P&gt;if first.chartno then last_postal = postal;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 20:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104379#M29167</guid>
      <dc:creator>Fugue</dc:creator>
      <dc:date>2013-08-07T20:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Extracting Data from Most Recent Record</title>
      <link>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104380#M29168</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thank you so much!!&amp;nbsp; That is exactly what I wanted!&amp;nbsp; &lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Aug 2013 21:05:57 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Procedures/Extracting-Data-from-Most-Recent-Record/m-p/104380#M29168</guid>
      <dc:creator>shellp55</dc:creator>
      <dc:date>2013-08-07T21:05:57Z</dc:date>
    </item>
  </channel>
</rss>

