<?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: Frequency in the prior 6 months in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563917#M158128</link>
    <description>&lt;P&gt;Thank you very much Patrick! I was able to get it to work finally. I really appreciate it..&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jun 2019 22:52:10 GMT</pubDate>
    <dc:creator>rosegarden81</dc:creator>
    <dc:date>2019-06-05T22:52:10Z</dc:date>
    <item>
      <title>Frequency in the prior 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563047#M157792</link>
      <description>&lt;P&gt;Hello All,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have this following sample data set as per the excel screenshot below (also attached as excel document ).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The data can be read in using the code below (for some reason, "date" isnt getting read in using datalines):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;data have;&lt;/P&gt;&lt;P&gt;infile datalines dsd truncover;&lt;/P&gt;&lt;P&gt;input Patient 2. Code $2. Index 2. Date mmddyy10.;&lt;BR /&gt;format date MMDDYY10.;&lt;BR /&gt;datalines;&lt;/P&gt;&lt;P&gt;1 AA 0 1/1/2015&lt;BR /&gt;1 BB 0 02/12/2016&lt;BR /&gt;1 CC 1 3/5/2016&lt;BR /&gt;1 DD 0 4/16/2016&lt;BR /&gt;1 EE 1 5/28/2016&lt;BR /&gt;1 FF 1 6/19/2016&lt;BR /&gt;1 GG 0 7/11/2016&lt;BR /&gt;1 HH 0 8/12/2016&lt;BR /&gt;1 AA 1 9/23/2016&lt;BR /&gt;1 JJ 1 12/15/2016&lt;BR /&gt;2 CC 1 11/26/2017&lt;BR /&gt;2 EE 0 12/1/2017&lt;BR /&gt;2 CC 0 1/29/2018&lt;BR /&gt;2 AA 1 2/20/2018&lt;BR /&gt;2 BB 1 3/14/2018&lt;BR /&gt;2 JJ 1 6/5/2018&lt;BR /&gt;2 AA 0 5/17/2018&lt;BR /&gt;2 HH 0 6/28/2018&lt;/P&gt;&lt;P&gt;;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic1.JPG" style="width: 400px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29947iEC27B2C0629E4D81/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pic1.JPG" alt="pic1.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want the frequency of Code for the prior 6 months corresponding to Index=1&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So whenever index=1 say on 5th March 2016, I want the frequency of 'Code' for 6 months prior to 6th March 2016.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In the above excel screenshot, the bold font are the variables that are in the dataset. The Index1, DiffDates: are just for demonstration which shows the difference between date (corresponding to Index=1) and the dates that occur prior to that per patient. Whenever this difference is &amp;lt;=180, I want to include such records in the frequency calculation of Code.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I want this frequency across all patients per screenshot below.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="pic2.JPG" style="width: 179px;"&gt;&lt;img src="https://communities.sas.com/t5/image/serverpage/image-id/29949i3D348D1328C37132/image-size/medium?v=v2&amp;amp;px=400" role="button" title="pic2.JPG" alt="pic2.JPG" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can see there is an INTNX function that allows me to output dates 180 days prior to the begin_date whenever index=1 but I think what I am trying to achieve is much more complicated than that. Any ideas how to produce such a frequency table would be greatly appreciated!!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Regards,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Tina&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2019 23:17:31 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563047#M157792</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-05-31T23:17:31Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency in the prior 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563060#M157794</link>
      <description>&lt;P&gt;I just wanted to add that here is my progress code which is not exactly getting the output but is almost there:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;proc sql;&lt;/P&gt;&lt;P&gt;create table counts as&lt;/P&gt;&lt;P&gt;select h1.patient, h1.date, h1.index, count(Code) as CountCodes&lt;/P&gt;&lt;P&gt;from have as h1&lt;/P&gt;&lt;P&gt;&amp;nbsp; INNER JOIN&lt;/P&gt;&lt;P&gt;have as h2&lt;/P&gt;&lt;P&gt;ON h2.date between intnx("day",h1.date,-180) and h1.date&lt;/P&gt;&lt;P&gt;group by patient, date ;&lt;/P&gt;&lt;P&gt;select * from count_codes&lt;/P&gt;&lt;P&gt;;quit;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think I am making a mistake in group by ...Any ideas?&lt;/P&gt;</description>
      <pubDate>Sat, 01 Jun 2019 00:11:17 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563060#M157794</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-06-01T00:11:17Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency in the prior 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563066#M157799</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/228108"&gt;@rosegarden81&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've added a few rows to your sample data. You're asking for a look-back period of 6 months but in your sample data all gaps are bigger within a patient and code.&lt;/P&gt;
&lt;P&gt;Does below return what you're after? And if not then can you explain how the desired result should look like using exactly the sample data posted.&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
  infile datalines dsd dlm=' ' truncover;
  input Patient :$8. Code :$2. Index :$1. Date :mmddyy10.;
  format date date9.;
  datalines;
1 AA 0 1/1/2015
1 AA 1 3/1/2015
1 AA 1 5/1/2015
1 AA 0 7/1/2015
1 AA 1 9/1/2015
1 AA 1 9/2/2015
1 AA 1 9/3/2015
1 BB 0 02/12/2016
1 CC 1 3/5/2016
1 DD 0 4/16/2016
1 EE 1 5/28/2016
1 FF 1 6/19/2016
1 GG 0 7/11/2016
1 HH 0 8/12/2016
1 AA 1 9/23/2016
1 JJ 1 12/15/2016
2 CC 1 11/26/2017
2 EE 0 12/1/2017
2 CC 0 1/29/2018
2 AA 1 2/20/2018
2 BB 1 3/14/2018
2 JJ 1 6/5/2018
2 AA 0 5/17/2018
2 HH 0 6/28/2018
;

proc sql;
/*  create table counts as*/
  select l.patient, l.code, l.date, count(*) as CountCodes
  from 
    have l left join have r
      on l.patient=r.patient and l.code=r.code 
          and r.date between intnx('month',l.date,-6,'s') and l.date   
    where l.index='1'
  group by l.patient, l.date, l.code
  ;
quit;
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Sat, 01 Jun 2019 01:06:14 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563066#M157799</guid>
      <dc:creator>Patrick</dc:creator>
      <dc:date>2019-06-01T01:06:14Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency in the prior 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563098#M157810</link>
      <description>Thank you very much Patrick!..I still couldn’t get this to work. I will post the results on Monday once we all get back to work &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;</description>
      <pubDate>Sat, 01 Jun 2019 16:22:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563098#M157810</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-06-01T16:22:47Z</dc:date>
    </item>
    <item>
      <title>Re: Frequency in the prior 6 months</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563917#M158128</link>
      <description>&lt;P&gt;Thank you very much Patrick! I was able to get it to work finally. I really appreciate it..&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jun 2019 22:52:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Frequency-in-the-prior-6-months/m-p/563917#M158128</guid>
      <dc:creator>rosegarden81</dc:creator>
      <dc:date>2019-06-05T22:52:10Z</dc:date>
    </item>
  </channel>
</rss>

