<?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 Subsetting in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815258#M321795</link>
    <description>&lt;P&gt;I have a long (i.e., not wide) dataset w/ 3 timepoints per participant:&lt;/P&gt;
&lt;TABLE border="0" width="181" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="181" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="181" height="21" class="xl65"&gt;baseline_arm_1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" class="xl65"&gt;fu_1_arm_1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" class="xl65"&gt;fu_2_arm_1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;I want to create a subset that only includes those who have completed all 3 timepoints. In the image below, the orange rows would be included and the&amp;nbsp;yellow rows would be excluded.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-05-26 at 9.29.45 AM.png" style="width: 491px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71798iD0E403C08B25ADCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-05-26 at 9.29.45 AM.png" alt="Screen Shot 2022-05-26 at 9.29.45 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I've tried various version of subsetting using WHERE, IN, OR, AND, etc.&lt;/P&gt;
&lt;P&gt;Seems like it should be pretty straight forward, but I can't figure it out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Thu, 26 May 2022 16:35:29 GMT</pubDate>
    <dc:creator>_maldini_</dc:creator>
    <dc:date>2022-05-26T16:35:29Z</dc:date>
    <item>
      <title>Subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815258#M321795</link>
      <description>&lt;P&gt;I have a long (i.e., not wide) dataset w/ 3 timepoints per participant:&lt;/P&gt;
&lt;TABLE border="0" width="181" cellspacing="0" cellpadding="0"&gt;&lt;COLGROUP&gt;&lt;COL width="181" /&gt;&lt;/COLGROUP&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="181" height="21" class="xl65"&gt;baseline_arm_1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" class="xl65"&gt;fu_1_arm_1&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD height="21" class="xl65"&gt;fu_2_arm_1&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;P&gt;I want to create a subset that only includes those who have completed all 3 timepoints. In the image below, the orange rows would be included and the&amp;nbsp;yellow rows would be excluded.&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Screen Shot 2022-05-26 at 9.29.45 AM.png" style="width: 491px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/71798iD0E403C08B25ADCE/image-size/large?v=v2&amp;amp;px=999" role="button" title="Screen Shot 2022-05-26 at 9.29.45 AM.png" alt="Screen Shot 2022-05-26 at 9.29.45 AM.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;I've tried various version of subsetting using WHERE, IN, OR, AND, etc.&lt;/P&gt;
&lt;P&gt;Seems like it should be pretty straight forward, but I can't figure it out.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 16:35:29 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815258#M321795</guid>
      <dc:creator>_maldini_</dc:creator>
      <dc:date>2022-05-26T16:35:29Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815259#M321796</link>
      <description>&lt;P&gt;It is complicated because you essentially need to process the data for each participant twice.&amp;nbsp; Once to check if all three events occurred and a second time to decide whether to output them.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;You could do that in a data step using two DO loops.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
  do until(last.participant);
    set have;
    by participant;
    if redcap_event_name='baseline_arm_1' then baseline=1;
    if redcap_event_name='fu_arm_1' then fu1=1;
    if redcap_event_name='fu_arm_2' then fu2=1;
  end;
  do until(last.participant);
    set have;
    by participant;
    if baseline and fu1 and fu2 then output;
  end;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 26 May 2022 16:48:21 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815259#M321796</guid>
      <dc:creator>Tom</dc:creator>
      <dc:date>2022-05-26T16:48:21Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815260#M321797</link>
      <description>&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/* UNTESTED CODE */
proc freq data=have;
    tables record_id/out=counts;
run;
data want;
    merge have counts;
    by record_id;
    if count=3;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;If you want tested code, please supply the data (not as a screen capture, we can't test code against a screen capture) but as SAS data step code, which you can type yourself or use &lt;A href="https://blogs.sas.com/content/sastraining/2016/03/11/jedi-sas-tricks-data-to-data-step-macro/" target="_self"&gt;these instructions&lt;/A&gt;. And you should provide data this way in your future questions.&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 16:44:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815260#M321797</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2022-05-26T16:44:10Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815261#M321798</link>
      <description>&lt;P&gt;proc sql;&lt;/P&gt;
&lt;P&gt;create table want as&lt;/P&gt;
&lt;P&gt;select * from have&lt;/P&gt;
&lt;P&gt;where record_id in (select record_id from have group by record_id having count (distinctr edcap_event_name) =3)&lt;/P&gt;
&lt;P&gt;order by 1, 2;&lt;/P&gt;
&lt;P&gt;quit;&lt;/P&gt;</description>
      <pubDate>Thu, 26 May 2022 16:51:13 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815261#M321798</guid>
      <dc:creator>Reeza</dc:creator>
      <dc:date>2022-05-26T16:51:13Z</dc:date>
    </item>
    <item>
      <title>Re: Subsetting</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815306#M321806</link>
      <description>&lt;P&gt;Assuming that the desired complete sets always occur in the sequence&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; baseline_arm_1&lt;BR /&gt;&amp;nbsp; &amp;nbsp; fu_1_arm_1&lt;/P&gt;
&lt;P&gt;&amp;nbsp; &amp;nbsp; fu_1_arm_2&lt;/P&gt;
&lt;P&gt;you can do a "lookahead" merge to determine whether the current record and the two subsequent records should be output (untested)::&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);

  merge have
        have (firstobs=2 keep=redcap_event_name rename=(redcap_event_name=_nxt_evnt))
        have (firstobs=3 keep=participant redcap_event_name rename=(participant=_nxt_part2 redcap_event_name=_nxt_evnt2));
  
  retain _counter 0;
  if _counter&amp;lt;=0 then do;  /*If not already in a threesome, then check the lookaheads */
    if redcap_event_name='baseline_arm_1'  and _nxt_evnt='fu_1_arm_1'  and _nxt_evnt2='fu_2_arm_2'
       and _nxtpart2=participant then _counter=3;
  end;

  if _counter&amp;gt;0;
  _counter+(-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Editted note:&amp;nbsp; slightly cleaner code below:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want (drop=_:);

  merge have
        have (firstobs=2 keep=redcap_event_name rename=(redcap_event_name=_nxt_evnt))
        have (firstobs=3 keep=participant redcap_event_name rename=(participant=_nxt_part2 redcap_event_name=_nxt_evnt2));
  
  retain _counter 0;
  if redcap_event_name='baseline_arm_1' then do;  /*If this is baseline, check the lookaheads */
     if _nxt_evnt='fu_1_arm_1'  and _nxt_evnt2='fu_2_arm_2' and _nxtpart2=participant then _counter=3;
  end;

  if _counter&amp;gt;0;
  _counter+(-1);
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 27 May 2022 22:40:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Subsetting/m-p/815306#M321806</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2022-05-27T22:40:53Z</dc:date>
    </item>
  </channel>
</rss>

