<?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: how to output subgroups of observations based on the other variable containing a certain value? in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352539#M82194</link>
    <description>&lt;P&gt;Assuming that records are sorted by patid and dates&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
do until(last.patid);
    set have; by patid;
    if death_status &amp;lt; max_death_status then clerical_error = 1;
    max_death_status = max(max_death_status, death_status);
    end;
do until(last.patid);
    set have; by patid;
    if clerical_error then output;
    end;
drop max_death_status clerical_error;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 23 Apr 2017 02:10:47 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-04-23T02:10:47Z</dc:date>
    <item>
      <title>how to output subgroups of observations based on the other variable containing a certain value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352537#M82193</link>
      <description>&lt;P&gt;My data contains multiple observations per patient and shows as that some of them readmitted after death (death_status=1) due to clerical errors. I'd like to extract those cases to data "want".&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
input patid death_status hosp_adm_year logical $;
datalines;
1	0	2000	yes
1	0	2001	yes
1	1	2002	yes
2	1	1995	no
2	0	1996	no
3	0	2000	no
3	1	2002	no
3	0	2003	no
4	1	1990	no
4	0	1992	no
4	1	1995	no
4	0	2000	no
5	0	1991	yes
5	0	1992	yes
5	0	1993	yes
;
run;

data want; 
input patid death_status hosp_adm_year logical $;
datalines;
2	1	1995	no
2	0	1996	no
3	0	2000	no
3	1	2002	no
3	0	2003	no
4	1	1990	no
4	0	1992	no
4	1	1995	no
4	0	2000	no
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Code below didn't work. Can I solve this problem in data steps somthing like this?&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data test; set have;
by patid;
if first.patid=0 or last.patid=0 then output;
where death_status=1; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Apr 2017 01:49:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352537#M82193</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-04-23T01:49:13Z</dc:date>
    </item>
    <item>
      <title>Re: how to output subgroups of observations based on the other variable containing a certain value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352539#M82194</link>
      <description>&lt;P&gt;Assuming that records are sorted by patid and dates&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
do until(last.patid);
    set have; by patid;
    if death_status &amp;lt; max_death_status then clerical_error = 1;
    max_death_status = max(max_death_status, death_status);
    end;
do until(last.patid);
    set have; by patid;
    if clerical_error then output;
    end;
drop max_death_status clerical_error;
run;&lt;/CODE&gt;&amp;nbsp;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 02:10:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352539#M82194</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-23T02:10:47Z</dc:date>
    </item>
    <item>
      <title>Re: how to output subgroups of observations based on the other variable containing a certain value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352545#M82199</link>
      <description>Elegant it is. Gotta learn this multiple SET statement programming. Thanks much!</description>
      <pubDate>Sun, 23 Apr 2017 02:30:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352545#M82199</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-04-23T02:30:28Z</dc:date>
    </item>
    <item>
      <title>Re: how to output subgroups of observations based on the other variable containing a certain value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352562#M82205</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&lt;/P&gt;
&lt;P&gt;Your code would not work, if one id 's death_status are all 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have; 
infile cards expandtabs ;
input patid death_status hosp_adm_year logical $;
datalines;
1	0	2000	yes
1	0	2001	yes
1	1	2002	yes
2	1	1995	no
2	0	1996	no
3	0	2000	no
3	1	2002	no
3	0	2003	no
4	1	1990	no
4	0	1992	no
4	1	1995	no
4	0	2000	no
5	0	1991	yes
5	0	1992	yes
5	0	1993	yes
6	1	1991	yes
6	1	1992	yes
6	1	1993	yes
;
run;



data want;
n=0;
do until(last.patid);
    set have; by patid;
    if death_status=1 then n+1;
    if death_status=1 and last.patid then last=1;
end;
do until(last.patid);
    set have; by patid;
    if n gt 1 or (n=1 and not last) then output;
end;
drop n;
run; &lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 23 Apr 2017 03:31:25 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352562#M82205</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2017-04-23T03:31:25Z</dc:date>
    </item>
    <item>
      <title>Re: how to output subgroups of observations based on the other variable containing a certain value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352568#M82206</link>
      <description>&lt;P&gt;Yeah, OP wanted to detect resurrections; you are going one step further, detecting multiple deaths&amp;nbsp;&lt;img id="smileyvery-happy" class="emoticon emoticon-smileyvery-happy" src="https://communities.sas.com/i/smilies/16x16_smiley-very-happy.png" alt="Smiley Very Happy" title="Smiley Very Happy" /&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 04:32:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352568#M82206</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-04-23T04:32:00Z</dc:date>
    </item>
    <item>
      <title>Re: how to output subgroups of observations based on the other variable containing a certain value?</title>
      <link>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352594#M82211</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/18408"&gt;@Ksharp&lt;/a&gt;, Thanks much. Detecting multiple death cases (1 all the way through) increased my end in the final output from 449 to 1372. I'm amazed. It shows that my deduplication efforts using probabilistic record linkage method is not perfect. All these 1372 needs a manual review now. I also like that indicator column created pointing to those specific cases.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 23 Apr 2017 13:50:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/how-to-output-subgroups-of-observations-based-on-the-other/m-p/352594#M82211</guid>
      <dc:creator>Cruise</dc:creator>
      <dc:date>2017-04-23T13:50:06Z</dc:date>
    </item>
  </channel>
</rss>

