<?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: Group by patients based on the condition in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625218#M184262</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Des1 Des2 Des3 Des4;
cards;
123 1 0 0 0
123 1 0 0 0
123 1 0 0 0
159 1 0 0 0
159 1 1 0 0
159 0 1 0 0
321 1 0 0 0
456 0 0 0 1
456 1 0 0 0
456 1 0 0 0
;
run;


data want;
  set have;
  by id;
  if first.id then elig = 1; retain elig;
  cond =  Des1=1 and sum(Des2, Des3, Des4) = 0 ;
  elig = elig * cond;
  if last.id and elig then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
    <pubDate>Mon, 17 Feb 2020 09:52:18 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2020-02-17T09:52:18Z</dc:date>
    <item>
      <title>Group by patients based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625212#M184257</link>
      <description>&lt;P&gt;Dear Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I need to fetch the IDs from my dataset based on group by condition.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'll share my sample data for your reference.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Des1 Des2 Des3 Des4;
cards;
123 1 0 0 0
123 1 0 0 0
123 1 0 0 0
159 1 0 0 0
159 1 1 0 0
159 0 1 0 0
321 1 0 0 0
456 0 0 0 1
456 1 0 0 0
456 1 0 0 0
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I expected output as IDs who are Deceased (Des1 =1) first and the rest of Des_ = 0.&amp;nbsp; (Output - 123, 321)&lt;/P&gt;&lt;P&gt;Kindly let me know for any clarification.&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 09:22:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625212#M184257</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-02-17T09:22:39Z</dc:date>
    </item>
    <item>
      <title>Re: Group by patients based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625217#M184261</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Like this?&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc means noprint;
	var Des1 Des2 Des3 Des4;
	class id;
	ways 1;
	output out=have_stat (drop=_:) n= sum= /autoname;
run;

data have_flag;
	set have_stat;
	flag_des1 = 0;
	if Des1_N = Des1_Sum then flag_des1=1; /* Identifies id 123 and 321 for example*/
	/*you can compute the flag for Des2, ... also */
run;

proc sql;
	create table want as
	select a.*, b.flag_des1
	from have as a inner join have_flag as b
	on a.id=b.id
	order by b.flag_des1 desc, a.id;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 17 Feb 2020 09:47:19 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625217#M184261</guid>
      <dc:creator>ed_sas_member</dc:creator>
      <dc:date>2020-02-17T09:47:19Z</dc:date>
    </item>
    <item>
      <title>Re: Group by patients based on the condition</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625218#M184262</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/215282"&gt;@Sathish_jammy&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Like this:&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Des1 Des2 Des3 Des4;
cards;
123 1 0 0 0
123 1 0 0 0
123 1 0 0 0
159 1 0 0 0
159 1 1 0 0
159 0 1 0 0
321 1 0 0 0
456 0 0 0 1
456 1 0 0 0
456 1 0 0 0
;
run;


data want;
  set have;
  by id;
  if first.id then elig = 1; retain elig;
  cond =  Des1=1 and sum(Des2, Des3, Des4) = 0 ;
  elig = elig * cond;
  if last.id and elig then output;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best&lt;/P&gt;&lt;P&gt;Bart&lt;/P&gt;</description>
      <pubDate>Mon, 17 Feb 2020 09:52:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Group-by-patients-based-on-the-condition/m-p/625218#M184262</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2020-02-17T09:52:18Z</dc:date>
    </item>
  </channel>
</rss>

