<?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: Selecting observations in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412661#M100929</link>
    <description>&lt;P&gt;For a non SQL solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
do until(last.patient_no);
    set diagnose; by patient_no notsorted;
    pos = pos or outcome = "Positive";
    neg = neg or outcome = "Negative";
    end;
do until(last.patient_no);
    set diagnose; by patient_no notsorted;
    if pos and neg then output;
    end;
drop pos neg;
run;

proc print noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
    <pubDate>Sun, 12 Nov 2017 07:13:36 GMT</pubDate>
    <dc:creator>PGStats</dc:creator>
    <dc:date>2017-11-12T07:13:36Z</dc:date>
    <item>
      <title>Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412658#M100926</link>
      <description>&lt;P&gt;I have the following data set, I am trying to select only observations&lt;/P&gt;&lt;P&gt;with at least 1 positive and 1 negative outcome. &amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Diagnose;
Input @1 Patient_No $2.
@3 Date MMDDYY10.
@14 Visit_No $2.
@16 Outcome $12.;
Format Date MMDDYY10.;
Datalines;
1 10/21/2000 1 Positive
1 10/25/2000 2 Positive
1 11/01/2000 3 Negative
1 05/28/2001 4 Negative
2 11/22/2000 1 Positive
2 11/29/2000 2 Positive
2 12/28/2000 3 Positive
2 06/28/2001 4 Low positive
2 10/29/2001 5 Negative
3 12/12/2000 1 Positive
3 12/29/2000 2 Positive
3 02/21/2001 3 Positive
3 07/12/2001 4 Negative
3 08/29/2001 5 Positive
4 08/29/2001 1 Positive
4 09/05/2001 2 Positive
4 11/01/2001 3 Positive
;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tried the following code.&lt;/P&gt;&lt;P&gt;data a;&lt;BR /&gt;set diagnose;&lt;BR /&gt;where outcome = "Positive" and "Negative";&lt;BR /&gt;proc print;&lt;BR /&gt;run;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 06:23:23 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412658#M100926</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-11-12T06:23:23Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412659#M100927</link>
      <description>&lt;P&gt;Beware of the cases where there are more than one distinct outcome but only one of them is Positive or Negative (patient_no = 5 below) :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;Data Diagnose;
Input @1 Patient_No $2.
@3 Date MMDDYY10.
@14 Visit_No $2.
@16 Outcome $12.;
Format Date MMDDYY10.;
Datalines;
1 10/21/2000 1 Positive
1 10/25/2000 2 Positive
1 11/01/2000 3 Negative
1 05/28/2001 4 Negative
2 11/22/2000 1 Positive
2 11/29/2000 2 Positive
2 12/28/2000 3 Positive
2 06/28/2001 4 Low positive
2 10/29/2001 5 Negative
3 12/12/2000 1 Positive
3 12/29/2000 2 Positive
3 02/21/2001 3 Positive
3 07/12/2001 4 Negative
3 08/29/2001 5 Positive
4 08/29/2001 1 Positive
4 09/05/2001 2 Positive
4 11/01/2001 3 Positive
5 11/22/2000 1 Low positive
5 11/29/2000 2 Negative
5 12/28/2000 3 Negative
5 06/28/2001 4 Negative
;

proc sql;
create table a as
select *
from diagnose
group by patient_no
having count( distinct 
    case outcome 
    when "Positive" then 1 
    when "Negative" then 2 
    else . end ) &amp;gt; 1
order by patient_no, visit_no;
select * from a;
quit;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Nov 2017 06:41:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412659#M100927</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-11-12T06:41:33Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412660#M100928</link>
      <description>&lt;P&gt;Yes, that works. Thank you for the addition of patient no 5.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 06:56:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412660#M100928</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-11-12T06:56:43Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412661#M100929</link>
      <description>&lt;P&gt;For a non SQL solution:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data b;
do until(last.patient_no);
    set diagnose; by patient_no notsorted;
    pos = pos or outcome = "Positive";
    neg = neg or outcome = "Negative";
    end;
do until(last.patient_no);
    set diagnose; by patient_no notsorted;
    if pos and neg then output;
    end;
drop pos neg;
run;

proc print noobs; run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sun, 12 Nov 2017 07:13:36 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412661#M100929</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-11-12T07:13:36Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412662#M100930</link>
      <description>&lt;P&gt;Since there's only one outcome value in your observations, it can never be positive and negative at the same time.&lt;/P&gt;
&lt;P&gt;Define what you consider an "observation"; in SAS speak, an observation is a single row of data in a dataset.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 07:17:42 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412662#M100930</guid>
      <dc:creator>Kurt_Bremser</dc:creator>
      <dc:date>2017-11-12T07:17:42Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412728#M100942</link>
      <description>@ PGStats, can you explan how does this code works?&lt;BR /&gt;pos = pos or outcome = "Positive";&lt;BR /&gt;I tried below, and it does not work.&lt;BR /&gt;pos = (outcome = "Positive");&lt;BR /&gt;</description>
      <pubDate>Sun, 12 Nov 2017 20:44:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412728#M100942</guid>
      <dc:creator>SAS_inquisitive</dc:creator>
      <dc:date>2017-11-12T20:44:29Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412752#M100947</link>
      <description>&lt;P&gt;Simple logic. At the start of a patient obs, pos is missing which is interpreted as False.&amp;nbsp;The logic&amp;nbsp;expression ensures that at each iteration over the&amp;nbsp;visits of a patient, if pos is already True, it remains True (True OR &amp;lt;&lt;EM&gt;anything&lt;/EM&gt;&amp;gt; = True), otherwise it becomes true if outcome="Positive".&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thus, after iterating over&amp;nbsp;a patients'&amp;nbsp;visits, pos = True if "Positive" was met at least once.&lt;/P&gt;</description>
      <pubDate>Sun, 12 Nov 2017 23:33:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412752#M100947</guid>
      <dc:creator>PGStats</dc:creator>
      <dc:date>2017-11-12T23:33:12Z</dc:date>
    </item>
    <item>
      <title>Re: Selecting observations</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412788#M100966</link>
      <description>&lt;P&gt;Yes, but the above example is transposed and ordered, should have pointed that out.&lt;/P&gt;</description>
      <pubDate>Mon, 13 Nov 2017 03:48:39 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Selecting-observations/m-p/412788#M100966</guid>
      <dc:creator>nerdy2703</dc:creator>
      <dc:date>2017-11-13T03:48:39Z</dc:date>
    </item>
  </channel>
</rss>

