<?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: Return one row per id by collapsing corrected values from later rows into first row. in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Return-one-row-per-id-by-collapsing-corrected-values-from-later/m-p/593145#M18133</link>
    <description>&lt;P&gt;Your logic is a little bit incomplete. It looks like what you want is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value from the first row for Datum, id, DayFromTxBase, CorrectionBas&lt;BR /&gt;The last non-missing value for Var1 through Var5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this correct?&lt;/P&gt;</description>
    <pubDate>Tue, 01 Oct 2019 17:38:26 GMT</pubDate>
    <dc:creator>TomKari</dc:creator>
    <dc:date>2019-10-01T17:38:26Z</dc:date>
    <item>
      <title>Return one row per id by collapsing corrected values from later rows into first row.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Return-one-row-per-id-by-collapsing-corrected-values-from-later/m-p/593061#M18130</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hello All,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope all is well. This is my first post since I've reviewed several others but unfortunately was not able to find the right solution to fit my circumstances.&amp;nbsp;I have a data set that requires me to provide: (1) one row per patient id, (2) collapsed (corrected) values from subsequent rows into the earliest patient record. Please see below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;EXAMPLE&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Datum&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp; DayFromTxBase&amp;nbsp; CorrectionBas Var1 Var2 Var3 Var4 Var5&lt;/P&gt;&lt;P&gt;1/27/2016 22:06&amp;nbsp; &amp;nbsp;Z029&amp;nbsp; -2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;ABC&amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;UVW&lt;/P&gt;&lt;P&gt;6/23/2017 15:36&amp;nbsp; &amp;nbsp;Z029&amp;nbsp; -2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;DEF&amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 5&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;XYZ&lt;/P&gt;&lt;P&gt;9/27/2019 10:37&amp;nbsp; &amp;nbsp;Z029&amp;nbsp; -2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GHI&amp;nbsp; &amp;nbsp;3&amp;nbsp; &amp;nbsp; &amp;nbsp;.&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; XYZ&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;U&gt;DESIRED RESULT&lt;/U&gt;&lt;/P&gt;&lt;P&gt;Datum&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;id&amp;nbsp; &amp;nbsp; &amp;nbsp; DayFromTxBase CorrectionBas Var1 Var2 Var3 Var4 Var5&amp;nbsp;&lt;/P&gt;&lt;P&gt;1/27/2016 22:06 Z029&amp;nbsp; -2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;GHI&amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; 4&amp;nbsp; &amp;nbsp; &amp;nbsp; XYZ&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've inherited some code from a colleague that runs an import macro which (1) checks the data set to see if there are corrections, and (2) if so, then make an original and a corrections data set, and (3) update the original values with corrected values. Please see below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%macro import2b(site=want);&lt;BR /&gt;proc import out=want&lt;BR /&gt;datafile="\\.."&lt;BR /&gt;dbms=xlsx replace ;&lt;BR /&gt;sheet= " ";&lt;BR /&gt;getnames=yes;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%symdel correct;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;/* checks the dataset if there are any corrections*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sql;&lt;BR /&gt;create table want as&lt;BR /&gt;select max(CORRECTIONBAS) as max_c,CORRECTIONBAS,*&lt;BR /&gt;from want ;&lt;BR /&gt;QUIT;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data want ;&lt;BR /&gt;%let correct=0;&lt;BR /&gt;set want;&lt;BR /&gt;call symput('correct',max_c);&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* if there are corrections then make a original dataset and a corrections dataset*/&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;%if &amp;amp;correct=1 %then&lt;BR /&gt;%do;&lt;/P&gt;&lt;P&gt;DATA ORIGINAL CORRECTION;&lt;BR /&gt;SET want;&lt;/P&gt;&lt;P&gt;if CORRECTIONBAS=. then&lt;BR /&gt;output ORIGINAL;&lt;/P&gt;&lt;P&gt;if CORRECTIONBAS=1 then&lt;BR /&gt;output CORRECTION;&lt;BR /&gt;RUN;&lt;BR /&gt;&lt;BR /&gt;proc sort data=original;&lt;BR /&gt;by ID DayFromTxBase;&lt;/P&gt;&lt;P&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;proc sort data=correction;&lt;BR /&gt;by ID DayFromTxBase;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;/* Update the original values (in original data)with corrected values (in corrected dataset)*/&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;DATA want;&lt;BR /&gt;UPDATE ORIGINAL CORRECTION;&lt;BR /&gt;BY ID DayFromTxBase;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;RUN;&lt;/P&gt;&lt;P&gt;proc datasets;&lt;BR /&gt;delete ORIGINAL CORRECTION;&lt;BR /&gt;run;&lt;/P&gt;&lt;P&gt;%end;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;%mend;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;import2b (site =want );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The long story short here is that this current program works for some patient ids and does not work (returns more than record) for other patient ids. Also, we've also advised to remove the DayFromTxBase column altogether as this data has been deemed to be unreliable, and thus we will likely devise a solution that sorts the tables by Datum. We've been wracking our brains on trying to figure this out, so hopefully there's someone out there who can help resolve this issue. Thank you.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 16:59:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Return-one-row-per-id-by-collapsing-corrected-values-from-later/m-p/593061#M18130</guid>
      <dc:creator>websitelogins94</dc:creator>
      <dc:date>2019-10-01T16:59:13Z</dc:date>
    </item>
    <item>
      <title>Re: Return one row per id by collapsing corrected values from later rows into first row.</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Return-one-row-per-id-by-collapsing-corrected-values-from-later/m-p/593145#M18133</link>
      <description>&lt;P&gt;Your logic is a little bit incomplete. It looks like what you want is:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The value from the first row for Datum, id, DayFromTxBase, CorrectionBas&lt;BR /&gt;The last non-missing value for Var1 through Var5&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Is this correct?&lt;/P&gt;</description>
      <pubDate>Tue, 01 Oct 2019 17:38:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Return-one-row-per-id-by-collapsing-corrected-values-from-later/m-p/593145#M18133</guid>
      <dc:creator>TomKari</dc:creator>
      <dc:date>2019-10-01T17:38:26Z</dc:date>
    </item>
  </channel>
</rss>

