<?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: Delete Prior Record in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279407#M56324</link>
    <description>&lt;P&gt;You would be better off merging the base record to empty record and coalescing the data:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  COALESCE(A.VAR1,B.VAR1) as VAR1,
          COALESCE(A.VAR2,B.VAR2) as VAR2
  from    (select * from HAVE where RECORD=1) A
  left join (select * from HAVE where RECORD=2) B
  on      A.IDVAR=B.IDVAR;
quit;&lt;/PRE&gt;
&lt;P&gt;As you have not presented test data ( in the form of a datastep) the above is purely an example and you will need ot modify to your data.&lt;/P&gt;</description>
    <pubDate>Wed, 22 Jun 2016 16:14:32 GMT</pubDate>
    <dc:creator>RW9</dc:creator>
    <dc:date>2016-06-22T16:14:32Z</dc:date>
    <item>
      <title>Delete Prior Record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279400#M56318</link>
      <description>&lt;P&gt;I have a data set where I'm using the prior row to populate data in the subsequent row with missing data. &amp;nbsp;I then need to delete the prior row. &amp;nbsp;Any ideas on how to properly do this?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data research.master;&lt;/P&gt;
&lt;P&gt;set research.prior;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;prev_value = lag(value);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;if id = lag(id) then do;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;if value = '' then value = prev_value;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; //I THEN NEED TO DELETE THE PRIOR ROW HERE&lt;/P&gt;
&lt;P&gt;end;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 15:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279400#M56318</guid>
      <dc:creator>akordula</dc:creator>
      <dc:date>2016-06-22T15:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Prior Record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279407#M56324</link>
      <description>&lt;P&gt;You would be better off merging the base record to empty record and coalescing the data:&lt;/P&gt;
&lt;PRE&gt;proc sql;
  create table WANT as
  select  COALESCE(A.VAR1,B.VAR1) as VAR1,
          COALESCE(A.VAR2,B.VAR2) as VAR2
  from    (select * from HAVE where RECORD=1) A
  left join (select * from HAVE where RECORD=2) B
  on      A.IDVAR=B.IDVAR;
quit;&lt;/PRE&gt;
&lt;P&gt;As you have not presented test data ( in the form of a datastep) the above is purely an example and you will need ot modify to your data.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 16:14:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279407#M56324</guid>
      <dc:creator>RW9</dc:creator>
      <dc:date>2016-06-22T16:14:32Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Prior Record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279408#M56325</link>
      <description>&lt;P&gt;The UPDATE statement does what you are looking for:&amp;nbsp; take in multiple records per ID, keep track of the latest nonmissing values, and output one record per ID.&amp;nbsp; Assuming your data set is sorted by ID, here is how it could be applied here:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;data research.master;&lt;/P&gt;
&lt;P&gt;update research.prior (obs=0) research.prior;&lt;/P&gt;
&lt;P&gt;by id;&lt;/P&gt;
&lt;P&gt;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This assumes that research.master does not exist prior to this step.&amp;nbsp; If it does, the program would have to change slightly (unless research.master can be replaced without losing important data).&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 16:17:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279408#M56325</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2016-06-22T16:17:19Z</dc:date>
    </item>
    <item>
      <title>Re: Delete Prior Record</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279527#M56341</link>
      <description>&lt;P&gt;Thanks!! This did exactly what I was looking for.&lt;/P&gt;</description>
      <pubDate>Wed, 22 Jun 2016 18:50:11 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Delete-Prior-Record/m-p/279527#M56341</guid>
      <dc:creator>akordula</dc:creator>
      <dc:date>2016-06-22T18:50:11Z</dc:date>
    </item>
  </channel>
</rss>

