<?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: Returns the Observation based on multiple conditions in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621371#M182669</link>
    <description>&lt;P&gt;&lt;SPAN&gt;I really appreciate your support.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Thank&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;you!&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 31 Jan 2020 05:35:33 GMT</pubDate>
    <dc:creator>Sathish_jammy</dc:creator>
    <dc:date>2020-01-31T05:35:33Z</dc:date>
    <item>
      <title>Returns the Observation based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621365#M182667</link>
      <description>&lt;P&gt;Hi Experts,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have patient data that contains information about Diseased/NonDiseased. I 'll share the sample dataset and the expected result for your reference.&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Vdate mmddyy10. DSD NDSD;
format Vdate mmddyy10.;
cards;
123 05/05/2000 0 1
123 08/04/2010 0 1
123 06/12/2012 1 0
123 12/02/2015 0 1
789 11/07/1998 1 0
789 10/08/2000 0 1
789 10/08/2000 0 1
951 02/02/2010 0 1
752 08/12/2019 1 0
521 09/09/2005 0 1
521 07/02/2009 1 0
;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I need all obs of IDs that are Nondiseased(NDSD=1) on their first visit date and Diseased(DSD=1 i.e NDSD=0) later on any occurrence.&lt;/P&gt;&lt;P&gt;Expected result: keep all obs of 123, 521 IDs.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 04:32:58 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621365#M182667</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-01-31T04:32:58Z</dc:date>
    </item>
    <item>
      <title>Re: Returns the Observation based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621367#M182668</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input ID Vdate mmddyy10. DSD NDSD;
format Vdate mmddyy10.;
cards;
123 05/05/2000 0 1
123 08/04/2010 0 1
123 06/12/2012 1 0
123 12/02/2015 0 1
789 11/07/1998 1 0
789 10/08/2000 0 1
789 10/08/2000 0 1
951 02/02/2010 0 1
752 08/12/2019 1 0
521 09/09/2005 0 1
521 07/02/2009 1 0
;

data want (drop=_:);
  set have;
  by id notsorted;
  if first.id=1 then _keep=ifn(ndsd=1,1,0);
  else if _keep=1 and (dsd=1 and ndsd=0) then _keep=2;
  retain _keep;

  if last.id then do until (last.id);
    set have;
    by id notsorted;
    if _keep=2 then output;
  end;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;This reads each ID group twice.&amp;nbsp; The first pass to determine the _KEEP variables based on your conditions.&amp;nbsp; The second pass to honor the _KEEP variable (outputting only when _KEEP=2).&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 04:56:09 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621367#M182668</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2020-01-31T04:56:09Z</dc:date>
    </item>
    <item>
      <title>Re: Returns the Observation based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621371#M182669</link>
      <description>&lt;P&gt;&lt;SPAN&gt;I really appreciate your support.&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG&gt;Thank&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 05:35:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621371#M182669</guid>
      <dc:creator>Sathish_jammy</dc:creator>
      <dc:date>2020-01-31T05:35:33Z</dc:date>
    </item>
    <item>
      <title>Re: Returns the Observation based on multiple conditions</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621424#M182680</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; Nice to see the question has been answered. For what it's worth, I would like to share an application of boolean expression in Proc SQL that I learned from&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/13976"&gt;@SASKiwi&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/462"&gt;@PGStats&lt;/a&gt;&amp;nbsp;a while ago. Hmm one is apparently burning in the heat down under while the other is freezing in the arctics. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
input ID Vdate mmddyy10. DSD NDSD;
format Vdate mmddyy10.;
cards;
123 05/05/2000 0 1
123 08/04/2010 0 1
123 06/12/2012 1 0
123 12/02/2015 0 1
789 11/07/1998 1 0
789 10/08/2000 0 1
789 10/08/2000 0 1
951 02/02/2010 0 1
752 08/12/2019 1 0
521 09/09/2005 0 1
521 07/02/2009 1 0
;
proc sql;
create table want as
select *
from have
where ID in (select ID from have group by id having min(vdate)=vdate and ndsd and max(vdate*dsd)&amp;gt;min(vdate))
order by id,vdate;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 Jan 2020 13:22:16 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Returns-the-Observation-based-on-multiple-conditions/m-p/621424#M182680</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2020-01-31T13:22:16Z</dc:date>
    </item>
  </channel>
</rss>

