<?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: Working with multiple obs for same person - choosing a particular obs in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765287#M242388</link>
    <description>&lt;P&gt;Assuming that HAVE is sorted by patient_id, the Double DOW-loop should do it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
input patient_id collection_date : $15. test_type : $15. test_result : $15.;
datalines;
1 3/1/2020 Antibody Positive
1 3/3/2020 PCR Positive
1 3/14/2020 PCR Negative
2 2/12/2020 Antibody Negative
2 4/10/2020 Antibody Positive
3 6/10/2020 Antibody Positive
3 6/15/2020 PCR Negative
;
RUN;

data want;
  do _N_ = 1 by 1 until(last.patient_id);
    set have;
    by patient_id;

    c1 + (test_type="Antibody" and test_result="Positive");
    c2 + (test_type="PCR");
  end;

  do _N_ = 1 to _N_;
    set have;
    if c1 and not c2 then output;
  end;

  c1=0;
  c2=0;
  drop c1 c2;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 01 Sep 2021 10:25:31 GMT</pubDate>
    <dc:creator>yabwon</dc:creator>
    <dc:date>2021-09-01T10:25:31Z</dc:date>
    <item>
      <title>Working with multiple obs for same person - choosing a particular obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765212#M242366</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;Sorry I don't have access to SAS right now (but using 9.4 at work), but I have a dataset like this:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;patient_id collection_date test_type test_result&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/1/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Antibody&amp;nbsp; Positive&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/3/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PCR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Positive&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;3/14/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PCR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Negative&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;2/12/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Antibody&amp;nbsp; &amp;nbsp;Negative&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;4/10/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Antibody&amp;nbsp; Positive&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/10/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Antibody&amp;nbsp; Positive&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;6/15/2020&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; PCR&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Negative&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Notice I have multiple obs. per patient, with multiple tests per patient.&amp;nbsp;I want to output to new table ONLY those patients that have Ab positive, but NO PCR done. So in this case, only patient_id 2 (second line showing Antibody Positive) should output because he had no PCR done. What's the best way to do this? I have a feeling with arrays, but I have not used them yet.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Thank you!&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 04:13:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765212#M242366</guid>
      <dc:creator>vegan_renegade</dc:creator>
      <dc:date>2021-09-01T04:13:12Z</dc:date>
    </item>
    <item>
      <title>Re: Working with multiple obs for same person - choosing a particular obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765240#M242378</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;use this:&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
input patient_id collection_date : $15. test_type : $15. test_result : $15.;
datalines;
1 3/1/2020 Antibody Positive
1 3/3/2020 PCR Positive
1 3/14/2020 PCR Negative
2 2/12/2020 Antibody Negative
2 4/10/2020 Antibody Positive
3 6/10/2020 Antibody Positive
3 6/15/2020 PCR Negative
;
RUN;

PROC SQL;
   CREATE TABLE have1 AS
      SELECT a.*,
            CASE 
               WHEN missing(b.patient_id) then 1
               ELSE 0
            END as noPCR_done
      FROM have a
      LEFT JOIN have b
      ON a.patient_id eq b.patient_id
      AND upcase(b.test_type) eq 'PCR'
      
   ORDER BY a.patient_id, a.collection_date, a.test_type
   ;
QUIT;

DATA want;
   set have1;
   *select patient having no PCR done and having any AB positive;
   where noPCR_done eq 1
   AND upcase(test_type) eq 'ANTIBODY' AND upcase(test_result) eq 'POSITIVE';
RUN;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 07:35:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765240#M242378</guid>
      <dc:creator>Oligolas</dc:creator>
      <dc:date>2021-09-01T07:35:07Z</dc:date>
    </item>
    <item>
      <title>Re: Working with multiple obs for same person - choosing a particular obs</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765287#M242388</link>
      <description>&lt;P&gt;Assuming that HAVE is sorted by patient_id, the Double DOW-loop should do it.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;DATA have;
input patient_id collection_date : $15. test_type : $15. test_result : $15.;
datalines;
1 3/1/2020 Antibody Positive
1 3/3/2020 PCR Positive
1 3/14/2020 PCR Negative
2 2/12/2020 Antibody Negative
2 4/10/2020 Antibody Positive
3 6/10/2020 Antibody Positive
3 6/15/2020 PCR Negative
;
RUN;

data want;
  do _N_ = 1 by 1 until(last.patient_id);
    set have;
    by patient_id;

    c1 + (test_type="Antibody" and test_result="Positive");
    c2 + (test_type="PCR");
  end;

  do _N_ = 1 to _N_;
    set have;
    if c1 and not c2 then output;
  end;

  c1=0;
  c2=0;
  drop c1 c2;
run;
proc print;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Bart&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 01 Sep 2021 10:25:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Working-with-multiple-obs-for-same-person-choosing-a-particular/m-p/765287#M242388</guid>
      <dc:creator>yabwon</dc:creator>
      <dc:date>2021-09-01T10:25:31Z</dc:date>
    </item>
  </channel>
</rss>

