<?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: Select &amp;amp; keep the most complete row in SAS Data Management</title>
    <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527475#M16347</link>
    <description>&lt;P&gt;Now to open up another can of worms ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose one visit was the only one that contained a measurement for SBP.&amp;nbsp; But that wasn't the visit with the most data.&amp;nbsp; Would you want to keep SBP from that visit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are easy ways to do this ... the program could actually be shorter than the solutions you have so far.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jan 2019 19:42:03 GMT</pubDate>
    <dc:creator>Astounding</dc:creator>
    <dc:date>2019-01-15T19:42:03Z</dc:date>
    <item>
      <title>Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527395#M16338</link>
      <description>&lt;P&gt;Hello!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am working on a study that we collected 6 different admission vitals for: systolic blood pressure, diastolic blood pressure, heart rate, respiratory rate, temp, and oximetry. The data came with up to three entries per patient and I would like to keep only one row that is the most complete with all the data from that timepoint. If there are multiple rows with the same amount of values collected the first recorded is the row we would like to keep. Any ideas on how to complete only the row with that is the most complete?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Example of data&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Patient ID&amp;nbsp; &amp;nbsp; &amp;nbsp; SBP&amp;nbsp; &amp;nbsp; &amp;nbsp; DBP&amp;nbsp; &amp;nbsp; &amp;nbsp;HR&amp;nbsp; &amp;nbsp; &amp;nbsp;RR&amp;nbsp; &amp;nbsp; TEMP&amp;nbsp; &amp;nbsp; OXIMETRY&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 120&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; 19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 36.6&amp;nbsp; &amp;nbsp; &amp;nbsp; 94&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 139&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 103&amp;nbsp; &amp;nbsp; &amp;nbsp; 75&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 122&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 101&amp;nbsp; &amp;nbsp; &amp;nbsp; 98&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 36.6&amp;nbsp; &amp;nbsp; &amp;nbsp; 94&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;------ This row is the desired row to keep&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 110&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;19&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 36.6&amp;nbsp; &amp;nbsp; &amp;nbsp; 94&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;lt;------ This row is the desired row to keep&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 109&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 76&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 102&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 81&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;18&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;lt;------ This row is the desired row to keep&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&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; 90&amp;nbsp; &amp;nbsp; &amp;nbsp; 82&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;17&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thanks for any help you can provide!&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Stephanie&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 17:11:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527395#M16338</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2019-01-15T17:11:03Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527399#M16339</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards truncover;
input PatientID      SBP      DBP     HR     RR    TEMP    OXIMETRY;
cards;
1                    120           . .                  19        36.6      94
1                    139        103      75       20     . . 
1                    122        101      98       18        36.6      94              
2                    110        . .                      19        36.6      94           
2                    109         .           76       20    . .                 
3                    102        81         .        18   . .                                    
3                      .            90      82       17   . .
;
data want;
do until(last.patientid);
set have;
by patientid;
k=n(of sbp--oximetry);
if first.patientid then m=k;
else m=max(m,k);
end;
do until(last.patientid);
set have;
by patientid;
if n(of sbp--oximetry)=m and not f then 
do;
output;
f=1;
end;
end;
drop m k f;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 17:25:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527399#M16339</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-01-15T17:25:30Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527401#M16340</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input Patient_ID $ SBP DBP HR RR TEMP  OXIMETRY;
datalines;
1 120 . . 19 36.2 94
1 139 103 75 20 . .
1 122 101 98 18 36.6 94
2 110 . . 19 36.6 94
2 110 . . 76 20 . .
3 102 81 . 18 . .
3 . 90 82 17 . .
;
run;

data tmp;
	set have;
	cnt=nmiss(SBP,DBP,HR,RR,TEMP,OXIMETRY);
run;

proc sort data= tmp out=tmp2 ;
	by Patient_ID cnt;
run;

data want;
	set tmp2;
	if first.Patient_ID;

	by Patient_ID;

	drop cnt;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jan 2019 17:31:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527401#M16340</guid>
      <dc:creator>r_behata</dc:creator>
      <dc:date>2019-01-15T17:31:00Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527406#M16341</link>
      <description>&lt;P&gt;This is a case where you want to use the N function (counts the number of non-missing numeric values among the arguments of N).&amp;nbsp; Luckily your variables of interest are all numeric.&amp;nbsp; Then just reread an output the observation with the first instance of maximum N function value for a given ID, which in your case benefits from the use of the SET statement with the POINT= option:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input ID      SBP      DBP     HR     RR    TEMP    OXIMETRY;
datalines;
1 120        .       .    19    36.6      94
1 139      103      75    20      .        .
1 122      101      98    18    36.6      94
2 110        .       .    19    36.6      94
2 109        .      76    20      .        .
3 102       81       .    18      .        .
3   .       90      82    17     .         .
run;
data want (drop=max_:);
  set have;
  by id;
  retain max_n max_ptr;
  if first.id then call missing(max_n,max_ptr);

  if n(sbp,dbp,hr,rr,temp,oximetry)&amp;gt;max_n then do;
    max_n=n(sbp,dbp,hr,rr,temp,oximetry);
    max_ptr=_n_;
  end;
  if last.id;
  set have point=max_ptr;
run;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 15 Jan 2019 17:39:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527406#M16341</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-15T17:39:49Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527416#M16342</link>
      <description>&lt;P&gt;This worked with retaining the row with the most responses, but did not always keep the first entry when multiple rows contained the same amount of missing variables.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply and help!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 18:21:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527416#M16342</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2019-01-15T18:21:07Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527418#M16343</link>
      <description>&lt;P&gt;This worked as well. I can't make all the replies a solution.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for all the help, very much appreciated!!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 18:22:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527418#M16343</guid>
      <dc:creator>sjarvis847</dc:creator>
      <dc:date>2019-01-15T18:22:23Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527425#M16345</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/223452"&gt;@r_behata&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I suspect you want to use&lt;/P&gt;
&lt;P&gt;&amp;nbsp; by patient_id DESCENDING cnt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 18:29:27 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527425#M16345</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2019-01-15T18:29:27Z</dc:date>
    </item>
    <item>
      <title>Re: Select &amp; keep the most complete row</title>
      <link>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527475#M16347</link>
      <description>&lt;P&gt;Now to open up another can of worms ...&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Suppose one visit was the only one that contained a measurement for SBP.&amp;nbsp; But that wasn't the visit with the most data.&amp;nbsp; Would you want to keep SBP from that visit?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;There are easy ways to do this ... the program could actually be shorter than the solutions you have so far.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jan 2019 19:42:03 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Data-Management/Select-amp-keep-the-most-complete-row/m-p/527475#M16347</guid>
      <dc:creator>Astounding</dc:creator>
      <dc:date>2019-01-15T19:42:03Z</dc:date>
    </item>
  </channel>
</rss>

