<?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 Count number of occurrences over time in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547214#M151590</link>
    <description>&lt;P&gt;Hello, I am working with a sample of health record data and I need some help writing a SAS program to answer a particular question from this data set. I need to know the total number of patients who have had &lt;U&gt;at least three prescriptions&lt;/U&gt; of drugA or drugB or drugC (it can be one or the other), at least 21 days apart over the past 6 months (let's say six months from today 3/29/19).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see below for an example of how the data set is organized. Of note, the date variables are numeric variables in DATETIME25.6 format. I am a relatively new SAS user so any help with this question would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Patient ID&amp;nbsp;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;U&gt;med_name&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;start_date&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;end_date&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp;09JAN2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10FEB2019&amp;nbsp; &amp;nbsp; &amp;nbsp;11FEB2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20MAR2019&amp;nbsp; &amp;nbsp; &amp;nbsp;20MAR2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugX&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06DEC2018&amp;nbsp; &amp;nbsp; &amp;nbsp;06DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01OCT2018&amp;nbsp; &amp;nbsp; &amp;nbsp;02OCT2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugD&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp;09JAN2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01NOV2018&amp;nbsp; &amp;nbsp; &amp;nbsp;08NOV2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12DEC2018&amp;nbsp; &amp;nbsp; &amp;nbsp;15DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp;17JAN2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; .....&lt;/P&gt;</description>
    <pubDate>Fri, 29 Mar 2019 14:36:53 GMT</pubDate>
    <dc:creator>wj2</dc:creator>
    <dc:date>2019-03-29T14:36:53Z</dc:date>
    <item>
      <title>Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547214#M151590</link>
      <description>&lt;P&gt;Hello, I am working with a sample of health record data and I need some help writing a SAS program to answer a particular question from this data set. I need to know the total number of patients who have had &lt;U&gt;at least three prescriptions&lt;/U&gt; of drugA or drugB or drugC (it can be one or the other), at least 21 days apart over the past 6 months (let's say six months from today 3/29/19).&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Please see below for an example of how the data set is organized. Of note, the date variables are numeric variables in DATETIME25.6 format. I am a relatively new SAS user so any help with this question would be much appreciated!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;&lt;U&gt;Patient ID&amp;nbsp;&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp;&amp;nbsp;&lt;U&gt;med_name&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;start_date&lt;/U&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;&lt;U&gt;end_date&lt;/U&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp;09JAN2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;10FEB2019&amp;nbsp; &amp;nbsp; &amp;nbsp;11FEB2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugA&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;20MAR2019&amp;nbsp; &amp;nbsp; &amp;nbsp;20MAR2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugX&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;06DEC2018&amp;nbsp; &amp;nbsp; &amp;nbsp;06DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugB&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01OCT2018&amp;nbsp; &amp;nbsp; &amp;nbsp;02OCT2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugD&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;07JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp;09JAN2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;01NOV2018&amp;nbsp; &amp;nbsp; &amp;nbsp;08NOV2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12DEC2018&amp;nbsp; &amp;nbsp; &amp;nbsp;15DEC2018&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; 3&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; drugC&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;12JAN2019&amp;nbsp; &amp;nbsp; &amp;nbsp;17JAN2019&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; .....&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 14:36:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547214#M151590</guid>
      <dc:creator>wj2</dc:creator>
      <dc:date>2019-03-29T14:36:53Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547232#M151599</link>
      <description>&lt;P&gt;May I seek some help in understanding your required output as there is no sample WANT for the sample HAVE&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Can the drugs be any or must it be only A,B or C.&lt;/P&gt;
&lt;P&gt;2. Can the same drug be prescribed or should it be different i.e The new start can for the same drug can start after the previous and be 21 days apart? will this qualify?&lt;/P&gt;
&lt;P&gt;3. Over the past 6 months? does that mean current day- 6 months "&lt;STRONG&gt;sameday" occurrence period alone qualify&amp;nbsp;?Anything beyond in the past need not considered?&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;4 A clear expected output for the sample explaining how and why (business requirement) will help in my opinion.&lt;/P&gt;
&lt;P&gt;5. Above all, somebody might have understood and perhaps the solution is on its way, but just in case--&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;For what it's worth, have a look the &lt;STRONG&gt;numofdays&lt;/STRONG&gt; column below and offer us a better intuition. Thank you&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;DIV class="branch"&gt;
&lt;DIV&gt;
&lt;DIV align="center"&gt;
&lt;TABLE class="table" summary="Procedure Print: Data Set WORK.WANT" frame="box" rules="all" cellspacing="0" cellpadding="5"&gt;
&lt;THEAD&gt;
&lt;TR&gt;
&lt;TH class="r header" scope="col"&gt;PatientID&lt;/TH&gt;
&lt;TH class="l header" scope="col"&gt;med_name&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;start_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;end_date&lt;/TH&gt;
&lt;TH class="r header" scope="col"&gt;numofdays&lt;/TH&gt;
&lt;/TR&gt;
&lt;/THEAD&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;drugA&lt;/TD&gt;
&lt;TD class="r data"&gt;07JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;09JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;drugA&lt;/TD&gt;
&lt;TD class="r data"&gt;10FEB2019&lt;/TD&gt;
&lt;TD class="r data"&gt;11FEB2019&lt;/TD&gt;
&lt;TD class="r data"&gt;32&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;1&lt;/TD&gt;
&lt;TD class="l data"&gt;drugA&lt;/TD&gt;
&lt;TD class="r data"&gt;20MAR2019&lt;/TD&gt;
&lt;TD class="r data"&gt;20MAR2019&lt;/TD&gt;
&lt;TD class="r data"&gt;37&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;&lt;FONT color="#FF0000"&gt;1&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="l data"&gt;&lt;FONT color="#FF0000"&gt;drugX&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="r data"&gt;&lt;FONT color="#FF0000"&gt;06DEC2018&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="r data"&gt;&lt;FONT color="#FF0000"&gt;06DEC2018&lt;/FONT&gt;&lt;/TD&gt;
&lt;TD class="r data"&gt;&lt;FONT color="#FF0000"&gt;-104&lt;/FONT&gt;&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;drugB&lt;/TD&gt;
&lt;TD class="r data"&gt;01OCT2018&lt;/TD&gt;
&lt;TD class="r data"&gt;02OCT2018&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;2&lt;/TD&gt;
&lt;TD class="l data"&gt;drugD&lt;/TD&gt;
&lt;TD class="r data"&gt;07JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;09JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;97&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;drugC&lt;/TD&gt;
&lt;TD class="r data"&gt;01NOV2018&lt;/TD&gt;
&lt;TD class="r data"&gt;08NOV2018&lt;/TD&gt;
&lt;TD class="r data"&gt;.&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;drugC&lt;/TD&gt;
&lt;TD class="r data"&gt;12DEC2018&lt;/TD&gt;
&lt;TD class="r data"&gt;15DEC2018&lt;/TD&gt;
&lt;TD class="r data"&gt;34&lt;/TD&gt;
&lt;/TR&gt;
&lt;TR&gt;
&lt;TD class="r data"&gt;3&lt;/TD&gt;
&lt;TD class="l data"&gt;drugC&lt;/TD&gt;
&lt;TD class="r data"&gt;12JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;17JAN2019&lt;/TD&gt;
&lt;TD class="r data"&gt;28&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Fri, 29 Mar 2019 15:15:33 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547232#M151599</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-29T15:15:33Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547243#M151606</link>
      <description>&lt;P&gt;Hi novinosrin,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you for your reply. Please see below for my answers to your questions.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. Can the drugs be any or must it be only A,B or C.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;FONT color="#FF0000"&gt;&lt;EM&gt;The drugs must be only A, B, or C.&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;2. Can the same drug be prescribed or should it be different i.e The new start can for the same drug can start after the previous and be 21 days apart? will this qualify?&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp; &lt;FONT color="#FF0000"&gt;&lt;EM&gt;Yes. The same drug can be prescribed as long as the start date is 21 days after the previous end date.&lt;/EM&gt;&lt;/FONT&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;3. Over the past 6 months? does that mean current day- 6 months "&lt;STRONG&gt;sameday" occurrence period alone qualify&amp;nbsp;?Anything beyond in the past need not considered?&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;&amp;nbsp; &amp;nbsp; Yes, anything beyond the past 6 months should not be considered. The &lt;SPAN style="font-size: 14px;"&gt;period&lt;/SPAN&gt;&amp;nbsp;should be between the current day (3/29/19) - 6 months from the current date (9/29/18). Prescriptions that began/ended on the start (3/29/19) and end (9/29/18) days of this period can be included.&amp;nbsp;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;4 A clear expected output for the sample explaining how and why (business requirement) will help in my opinion.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &amp;nbsp;&lt;FONT color="#FF0000"&gt;&lt;EM&gt;Regarding an expected output, I would simply just like the total number of patients that meet this criteria. Therefore, a binary variable could be created for each patient (yes/no) indicating whether they meet the criteria and I could run proc freq to get total count. Other suggestions are welcome too.&amp;nbsp;&lt;/EM&gt;&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 15:35:56 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547243#M151606</guid>
      <dc:creator>wj2</dc:creator>
      <dc:date>2019-03-29T15:35:56Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547246#M151607</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115194"&gt;@wj2&lt;/a&gt;&amp;nbsp; &amp;nbsp;See if this works and let me know&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data have;
infile cards truncover;
input PatientID       med_name   $    (start_date       end_date) (:date9.);
format start_date       end_date date9.;
cards;
      1                    drugA           07JAN2019     09JAN2019
      1                    drugA           10FEB2019     11FEB2019
      1                    drugA           20MAR2019     20MAR2019
      1                    drugX           06DEC2018     06DEC2018
      2                    drugB           01OCT2018     02OCT2018
      2                    drugD           07JAN2019     09JAN2019
      3                    drugC           01NOV2018     08NOV2018
      3                    drugC           12DEC2018     15DEC2018
      3                    drugC           12JAN2019     17JAN2019
	  ;


proc sort data=have(where=(med_name in ('drugA','drugB','drugC') and  
intnx('month',today(),-6,'s')&amp;lt;=start_date&amp;lt;=today())) out=_have;
by PatientID start_date end_date;
run;

data want;
set _have;
by PatientID start_date end_date;
k=lag(end_date);
if first.PatientID then c=1;
else if intck('days',k,start_date)&amp;gt;=21 then c+1;
if c&amp;gt;=3 and last.PatientID;
drop k c;
run;

/*Now run a proc freq and all kinds of count methods you want as you wish*/&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Mar 2019 15:54:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547246#M151607</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-29T15:54:30Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547277#M151626</link>
      <description>&lt;P&gt;Hi &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;, I received an error message in the log indicating the input data set (meds2) is empty. Any suggestions? I have provided my code below. You'll see that I am first trying to change the date variables from DATETIME25.6 to date9. format. Forgive me for any naivety here.&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data meds2;
set meds;
format start_date date9.;
informat start_date date9.;
format end_date date9.;
informat end_date date9.;
run;

proc sort data=meds2 (where=(med_name in ('drugA', 'drugB', 'drugC') and 
intnx('month',today(),-6,'s')&amp;lt;=start_date&amp;lt;=today())) out=meds3;
by patientID start_date end_date;
run;

data meds4;
set meds3;
by PatientID start_date end_date;
k=lag(end_date);
if first.PatientID then c=1;
else if intck('days',k,start_date)&amp;gt;=21 then c+1;
if c&amp;gt;=3 and last.PatientID;
drop k c;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 29 Mar 2019 17:26:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547277#M151626</guid>
      <dc:creator>wj2</dc:creator>
      <dc:date>2019-03-29T17:26:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547280#M151628</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115194"&gt;@wj2&lt;/a&gt;&amp;nbsp; My understanding is your datetime(number of seconds from Jan1,1960) rather than&amp;nbsp; date(number of days since jan1,1960) of course formatted as Datetime appropriately for display.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Okay no worries&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;Extract the date from datetime value using Datepart function like this&lt;/STRONG&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token procnames"&gt;data&lt;/SPAN&gt; meds2&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;set&lt;/SPAN&gt; meds&lt;SPAN class="token punctuation"&gt;;&lt;BR /&gt;&lt;/SPAN&gt;_start=datepart(start);&lt;BR /&gt;_end=datepart(end);
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; start_date date9&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;informat&lt;/SPAN&gt; start_date date9&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; end_date date9&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token statement"&gt;informat&lt;/SPAN&gt; end_date date9&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;run&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Use the _&amp;nbsp; prefixed extracted date variables in the logic I gave you.&lt;/P&gt;
&lt;P&gt;--------------------------------------------------------------------------------------------------------&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Alternatively, you could do revise to&amp;nbsp;&amp;nbsp;&lt;STRONG&gt;datepart(start_date)&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE class=" language-sas"&gt;&lt;CODE class="  language-sas"&gt;&lt;SPAN class="token function"&gt;intnx&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'month'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;today&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;-6&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'s'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token operator"&gt;&amp;lt;=datepart(&lt;/SPAN&gt;start_date)&lt;SPAN class="token operator"&gt;&amp;lt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;today&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt; out&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;meds3&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;everywhere in the same code wherever the date variables are referenced but to make the process smooth, the former is a more neat process. HTH&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;PS&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Format is just for display and do not confuse as though that can be used to extract &lt;STRONG&gt;date&lt;/STRONG&gt; value from a &lt;STRONG&gt;datetime&lt;/STRONG&gt; value&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 17:43:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547280#M151628</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-29T17:43:32Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547317#M151650</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;Thank you! This ended up fixing the issue.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, I may have misspoke, but the start date for each prescription should be at least 21 days after the previous start date (not end date). Is this how you understand it and provided the code for or should the code be modified to reflect this criteria?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 19:10:38 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547317#M151650</guid>
      <dc:creator>wj2</dc:creator>
      <dc:date>2019-03-29T19:10:38Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547321#M151652</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115194"&gt;@wj2&lt;/a&gt;&amp;nbsp;&amp;nbsp; My understanding for each Patientid is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Current row's start - previous row's end&amp;nbsp; &lt;STRONG&gt;&amp;gt;= &lt;/STRONG&gt;21&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know your requirement&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 19:18:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547321#M151652</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-29T19:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547322#M151653</link>
      <description>&lt;P&gt;It should actually be: current row's start_date - previous row's start_date = &amp;gt;=21&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;How do you suggest modifying the code to meet this criteria?&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 19:23:41 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547322#M151653</guid>
      <dc:creator>wj2</dc:creator>
      <dc:date>2019-03-29T19:23:41Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547325#M151655</link>
      <description>&lt;P&gt;Ok&amp;nbsp;&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115194"&gt;@wj2&lt;/a&gt;&amp;nbsp; &amp;nbsp;At 2:27&amp;nbsp; Central Time Chicago, I am starving. So I am stepping out for lunch. Will be back in like 30 mins or so to modify the code. Bear with me&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 19:28:49 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547325#M151655</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-29T19:28:49Z</dc:date>
    </item>
    <item>
      <title>Re: Count number of occurrences over time</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547329#M151658</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/115194"&gt;@wj2&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, The only change is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;k=lag(&lt;FONT color="#339966"&gt;start_date&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;instead of&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;EM&gt;&lt;STRONG&gt;k=lag(&lt;FONT color="#FF0000"&gt;end_date&lt;/FONT&gt;);&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please test and let me know&lt;/P&gt;</description>
      <pubDate>Fri, 29 Mar 2019 19:51:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Count-number-of-occurrences-over-time/m-p/547329#M151658</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-03-29T19:51:32Z</dc:date>
    </item>
  </channel>
</rss>

