<?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: Keep only sample with at lease 3 visits in New SAS User</title>
    <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925690#M41554</link>
    <description>Thank you so much!! I’m always grateful for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
    <pubDate>Thu, 25 Apr 2024 03:47:53 GMT</pubDate>
    <dc:creator>tan-wongv</dc:creator>
    <dc:date>2024-04-25T03:47:53Z</dc:date>
    <item>
      <title>Keep only sample with at lease 3 visits</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925680#M41552</link>
      <description>&lt;P&gt;I have a data set as follow. Dx_Date refers to the date of each visit. I would like to keep only sample who have &amp;gt;= 3 visits. &lt;BR /&gt;In this case, only sample with DMRN 10 and 13 will be kept. What code should I use? Thank you&lt;/P&gt;
&lt;TABLE style="width: 50px;" border="1" width="50"&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;DMRN&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;DX_DATE&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;Age&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;2&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;09MAY2022&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;73&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;4&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;09APR2021&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;58&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;01JAN2017&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;60&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;03FEB2018&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;61&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;10&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;06JUN2018&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;61&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;13&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;08FEB2017&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;70&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;13&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;09JUL2017&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;70&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;13&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;12MAR2019&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;72&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD width="58.7969px" height="30px"&gt;13&lt;/TD&gt;
&lt;TD width="101.719px" height="30px"&gt;25DEC2019&lt;/TD&gt;
&lt;TD width="40px" height="30px"&gt;72&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Thu, 25 Apr 2024 02:23:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925680#M41552</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-25T02:23:14Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only sample with at lease 3 visits</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925688#M41553</link>
      <description>&lt;P&gt;Below two options how to achieve this.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For option 1: If your source data isn't already sorted by&amp;nbsp;DMRN and DX_DATE then you need to add a Proc Sort.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  input DMRN DX_DATE:date9. Age;
  format DX_DATE date9.;
datalines;
2 09MAY2022 73
4 09APR2021 58
10 01JAN2017 60
10 03FEB2018 61
10 06JUN2018 61
13 08FEB2017 70
13 09JUL2017 70
13 12MAR2019 72
13 25DEC2019 72
;

/* option 1 */
data visit_cnt(keep=DMRN visits);
  set have;
  by DMRN DX_DATE;
  if first.dmrn then visits=1;
  else visits+1;
  if last.dmrn then output;
run;

data want1;
  merge have visit_cnt;
  by dmrn;
  if visits&amp;gt;=3;
run;

/* option 2 */
proc sql;
  create table want2 as
  select *, count(*) as visits
  from have
  group by dmrn
  having visits&amp;gt;=3
  order by dmrn, dx_date
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 25 Apr 2024 03:20:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925688#M41553</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2024-04-25T03:20:43Z</dc:date>
    </item>
    <item>
      <title>Re: Keep only sample with at lease 3 visits</title>
      <link>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925690#M41554</link>
      <description>Thank you so much!! I’m always grateful for your help &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Thu, 25 Apr 2024 03:47:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/New-SAS-User/Keep-only-sample-with-at-lease-3-visits/m-p/925690#M41554</guid>
      <dc:creator>tan-wongv</dc:creator>
      <dc:date>2024-04-25T03:47:53Z</dc:date>
    </item>
  </channel>
</rss>

