<?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: Longitudinal data - flag missing yet keeping available info in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494140#M130166</link>
    <description>&lt;P&gt;Assuming I understood what you mean.&lt;/P&gt;&lt;P&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id n_visits value value_now;
cards;
1 1 22 21
1 2 23 23
1 3 . .
1 4 . .
2 1 . .
2 2 . .
2 3 56 .
2 4 . .
2 5 . .
3 1 23 .
3 2 . .
3 3 . .
4 1 . .
5 1 22 .
6 1 . .
6 2 . .
6 3 . .
;
proc sql;
create table temp as
select *
 from have
  where value is not missing or value_now is not missing;
create table missing as
 select * from have where  patient_id not in (select patient_id from temp)
  order by 1,2;
quit;
data missing_first;
 set missing;
 by patient_id;
 if first.patient_id;
run;
data want;
 set temp missing_first;
 by patient_id n_visits;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;</description>
    <pubDate>Mon, 10 Sep 2018 14:42:56 GMT</pubDate>
    <dc:creator>Ksharp</dc:creator>
    <dc:date>2018-09-10T14:42:56Z</dc:date>
    <item>
      <title>Longitudinal data - flag missing yet keeping available info</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494126#M130159</link>
      <description>&lt;P&gt;I have patients test values recorded at their each of visits (n_visits). There are missing&amp;nbsp;in test values in different patterns. I want to keep all the available information while removing rows with missing while tracking for patients who had no test value at all visits (patient 4 and 6).&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;What would be a solution to flag patients 4 and 6 to indicate that they had no test values at all while keeping other patients information yet getting rid of missing rows?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks!!!!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id n_visits value value_now;
cards;
1 1 22 21
1 2 23 23
1 3 . .
1 4 . .
2 1 . .
2 2 . .
2 3 56 .
2 4 . .
2 5 . .
3 1 23 .
3 2 . .
3 3 . .
4 1 . .
5 1 22 .
6 1 . .
6 2 . .
6 3 . .
;
data want;
input patient_id n_visits value value_now flag_missing;
cards;
1 1 22 21 0
1 2 23 23 0
2 3 56 . 0
3 1 23 . 0
4 1 . . 1
5 1 22 . 0
6 1 . . 1
;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Sep 2018 13:49:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494126#M130159</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2018-09-10T13:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: Longitudinal data - flag missing yet keeping available info</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494140#M130166</link>
      <description>&lt;P&gt;Assuming I understood what you mean.&lt;/P&gt;&lt;P&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;&lt;P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id n_visits value value_now;
cards;
1 1 22 21
1 2 23 23
1 3 . .
1 4 . .
2 1 . .
2 2 . .
2 3 56 .
2 4 . .
2 5 . .
3 1 23 .
3 2 . .
3 3 . .
4 1 . .
5 1 22 .
6 1 . .
6 2 . .
6 3 . .
;
proc sql;
create table temp as
select *
 from have
  where value is not missing or value_now is not missing;
create table missing as
 select * from have where  patient_id not in (select patient_id from temp)
  order by 1,2;
quit;
data missing_first;
 set missing;
 by patient_id;
 if first.patient_id;
run;
data want;
 set temp missing_first;
 by patient_id n_visits;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;BR data-mce-bogus="1" /&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 10 Sep 2018 14:42:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494140#M130166</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2018-09-10T14:42:56Z</dc:date>
    </item>
    <item>
      <title>Re: Longitudinal data - flag missing yet keeping available info</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494142#M130168</link>
      <description>&lt;P&gt;You want to delete all records with value missing, EXCEPT keep one record for any patient with all missing values.&amp;nbsp; This program does that:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id n_visits value value_now;
cards;
1 1 22 21
1 2 23 23
1 3 . .
1 4 . .
2 1 . .
2 2 . .
2 3 56 .
2 4 . .
2 5 . .
3 1 23 .
3 2 . .
3 3 . .
4 1 . .
5 1 22 .
6 1 . .
6 2 . .
6 3 . .
;
data want (drop=_:);
  set have;
  by patient_id;
  if first.patient_id then _nzeroes=0;
  if value^=. then flag=0;
  _nzeroes+(flag=0);
  if last.patient_id and _nzeroes=0 then flag=1;
  if flag=1 or flag=0;  
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, instead of keeping the first record for id 6, this keeps the last - which you might actually prefer, since n_visit becomes the number of visit records for that patient.&amp;nbsp; But if you actually want to keep the first record:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id n_visits value value_now;
cards;
1 1 22 21
1 2 23 23
1 3 . .
1 4 . .
2 1 . .
2 2 . .
2 3 56 .
2 4 . .
2 5 . .
3 1 23 .
3 2 . .
3 3 . .
4 1 . .
5 1 22 .
6 1 . .
6 2 . .
6 3 . .
;
data want (drop=_:);
  set have;
  by patient_id;
  if first.patient_id then do;
    _nzeroes=0;
    _firstrec=_n_;
  end;
  if value^=. then flag=0;
  _nzeroes+(flag=0);
  if last.patient_id and _nzeroes=0 then do;
    set have point=_firstrec;
    flag=1;
  end;
  if flag=1 or flag=0;  
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Sep 2018 14:45:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494142#M130168</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2018-09-10T14:45:42Z</dc:date>
    </item>
    <item>
      <title>Re: Longitudinal data - flag missing yet keeping available info</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494154#M130175</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input patient_id n_visits value value_now;
cards;
1 1 22 21
1 2 23 23
1 3 . .
1 4 . .
2 1 . .
2 2 . .
2 3 56 .
2 4 . .
2 5 . .
3 1 23 .
3 2 . .
3 3 . .
4 1 . .
5 1 22 .
6 1 . .
6 2 . .
6 3 . .
;

proc sql;
create table want(drop=r) as
select *,missing(value) as flag_missing,range(calculated flag_missing) as r
from have
group by patient_id
having ((r=0)*n_visits)=min(n_visits) or (value ne .)
order by patient_id,n_visits;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 10 Sep 2018 15:34:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Longitudinal-data-flag-missing-yet-keeping-available-info/m-p/494154#M130175</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2018-09-10T15:34:50Z</dc:date>
    </item>
  </channel>
</rss>

