<?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: Trying to create a new binary variable based on a rolling time window in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551749#M153334</link>
    <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Do you ever doubt I would disagree to your wise advice. If yes, change that. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, I haven't used ETS much so I don't know much about it. 2nd, I am attempting with what I know. When all we have is a hammer, everything looks like a nail.&lt;/P&gt;</description>
    <pubDate>Wed, 17 Apr 2019 14:23:43 GMT</pubDate>
    <dc:creator>novinosrin</dc:creator>
    <dc:date>2019-04-17T14:23:43Z</dc:date>
    <item>
      <title>Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551382#M153180</link>
      <description>&lt;P&gt;Hi folks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a dataset that looks like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input studyID mth_date ed_visits year ;
cards;
1 2011-04 0 2011
1 2011-05 1 2011
1 2012-01 3 2012
2 2011-03 4 2011
3 2011-04 2 2011
3 2011-06 0 2011
3 2013-08 2 2013
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;And I'm trying to create a dataset that will tell me which of the study id's have 3 or more ed_visits within 12 months ( we'll call them repeat users). The trick is that I don't care if it's 3 hospitalizations in the same year, just that within any 12 month period they have a total of 3 or more hospitalizations. So Using the above dataset, and creating a binary variable for "repeat user" my output could look something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input studyID mth_date ed_visits year Repeat_user ;
cards;
1 2011-04 0 2011 1
1 2011-05 1 2011 1
1 2012-01 3 2012 1
2 2011-03 4 2011 1
3 2011-04 2 2011 0
3 2011-06 0 2011 0
3 2013-08 2 2013 0
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Study ID's 1 and 2 both have enough hospitalizations to qualify as repeat users (value of 1),&amp;nbsp; but #3 never had more than 2 visits within a 12 month period, so they remain 0's.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Alternatively,&amp;nbsp; a list of the study ID's that meet the "repeat user" criteria would also work.&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Also, just FYI the mnth_date variable is currently not a SAS date, just a string (not my fault that's just how the data came).&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In essence I need to be able to sort out the people who made 3 or more trips to the ED within 12 months over the course of my study period&amp;nbsp; from those that haven't&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts would be much appreciated!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 14:21:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551382#M153180</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-16T14:21:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551404#M153195</link>
      <description>&lt;P&gt;PROC EXPAND will do this, it can count the sum of the ed_visits over a rolling X month time period. Once you have the rolling sum, you can create a binary variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a hint to help this work, you are going to need to make sure your mth_date is an actual SAS date value. (As it stands, your input statement will fail to read 2011-04, for example. Perhaps there is an informat that will allow mth_date to be read as an actual SAS date value). Once you straighten that out, you can add in zeros for months that don't appear in data set HAVE, so that PROC EXPAND can work on 12 consecutive months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:21:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551404#M153195</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-16T15:21:18Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551422#M153205</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;&amp;nbsp; &amp;nbsp;See if this works. If my understanding is correct, proc sql is rather easier. I fancied a DOW Hash for FWIW.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input studyID mth_date $ ed_visits year ;
md=input(compress(mth_date,'-'),yymmn6.);
format md date9.;
cards;
1 2011-04 0 2011
1 2011-05 1 2011
1 2012-01 3 2012
2 2011-03 4 2011
3 2011-04 2 2011
3 2011-06 0 2011
3 2013-08 2 2013
;
run;


data want;
if _n_=1 then do;
	if 0 then set have;
   dcl hash H (dataset:'have',ordered: "A",multidata:'y') ;
   h.definekey  ("studyID") ;
   h.definedata ("md","ed_visits") ;
   h.definedone () ;
end;
_k=0;
do until(last.studyid);
set have(rename=(md=_md ed_visits=_ed_visits));
by studyID;
do rc=h.find() by 0 while(rc=0);
if md&amp;gt;_md and intck('month',_md,md)&amp;lt;=12 then k=sum(ed_visits,_ed_visits);
rc=h.find_next();
end;
_k+k;
repeat_user=first.studyid and last.studyid and _ed_visits&amp;gt;=3  or k&amp;gt;=3 ;
end;
do until(last.studyid);
set have;
by studyID;
output;
end;
keep studyid mth_date ed_visits year repeat_user;
run;
&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:54:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551422#M153205</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-16T15:54:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551423#M153206</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;PROC EXPAND will do this, it can count the sum of the ed_visits over a rolling X month time period. Once you have the rolling sum, you can create a binary variable.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As a hint to help this work, you are going to need to make sure your mth_date is an actual SAS date value. (As it stands, your input statement will fail to read 2011-04, for example. Perhaps there is an informat that will allow mth_date to be read as an actual SAS date value). Once you straighten that out, you can add in zeros for months that don't appear in data set HAVE, so that PROC EXPAND can work on 12 consecutive months.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;The anydtdte informat will read those values as the first of the month:&lt;/P&gt;
&lt;PRE&gt;data have;
input studyID mth_date :anydtdte10. ed_visits year ;
format mth_date date9.;
cards;
1 2011-04 0 2011
1 2011-05 1 2011
1 2012-01 3 2012
2 2011-03 4 2011
3 2011-04 2 2011
3 2011-06 0 2011
3 2013-08 2 2013
run;&lt;/PRE&gt;</description>
      <pubDate>Tue, 16 Apr 2019 15:37:45 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551423#M153206</guid>
      <dc:creator>ballardw</dc:creator>
      <dc:date>2019-04-16T15:37:45Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551476#M153233</link>
      <description>&lt;P&gt;Hi folks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still working on the main problem, but fyi here is the solution that worked for fixing the date variable...... (current format is a string that looks like '2011-04')&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
set have;
format date2 date9.;
date2 = input(mthdate,anydtdte10.);
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where date2 is the corrected date variable, and mthdate is the original string variable.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;hoping it can help someone else in a similar situation down the line, will report back when I get the rest sorted out.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2019 17:37:37 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551476#M153233</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-16T17:37:37Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551728#M153321</link>
      <description>&lt;P&gt;Thanks so much for this Novinosrin.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I've given the code a try, and it looks like it's running, but it's been chugging away for about ten hours now. Any thoughts on why that might be?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 13:55:04 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551728#M153321</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-17T13:55:04Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551730#M153323</link>
      <description>&lt;P&gt;How large is your dataset? I hope there isn't any memory constraints&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I ran against your sample and I trust that's a representative one. Nonetheless, I can work on a SQL solution as a parallel alternative if needed. Keep us posted.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 13:59:12 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551730#M153323</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-17T13:59:12Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551734#M153325</link>
      <description>It's a biggie I'm afraid. (approx, 5.6 million records total for approx 104,000 individuals). The sample is representative of the data format, but clearly not the size. Re: memory constraints I'm checking with the administrator now. My guess is that's what the issue is. would Proc SQL help to take some of the load off?&lt;BR /&gt;&lt;BR /&gt;Thanks so much for working through this with me. It's much appreciated.</description>
      <pubDate>Wed, 17 Apr 2019 14:02:26 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551734#M153325</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-17T14:02:26Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551741#M153330</link>
      <description>&lt;P&gt;Just&amp;nbsp;&lt;SPAN&gt;&lt;STRONG&gt;5.6 million&lt;/STRONG&gt; records&amp;nbsp;?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Jeez, that's tiny. I was thinking a few 100 millions. Are you saying it's been running for 10 hours?Hmm that can't be true. &lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did you paste the code correctly checking word by word before you started executing?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Did you test on a smaller sample to begin with and see if that works&lt;/SPAN&gt;&lt;SPAN&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;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Anyways, I will test against 100 million in a bit on my machine and respond here but I don't think that will have any issues here. Nonetheless, I will be right back with SQL solution shortly after a coffee&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 14:07:32 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551741#M153330</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-17T14:07:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551744#M153331</link>
      <description>&lt;P&gt;Why use SQL or hash, when SAS has already programmed exactly what you need in PROC EXPAND?&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;(One possible reason is that your SAS license does not contain PROC EXPAND, but this hasn't been stated by the OP)&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 14:20:47 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551744#M153331</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-17T14:20:47Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551749#M153334</link>
      <description>&lt;P&gt;Sir&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp; Do you ever doubt I would disagree to your wise advice. If yes, change that. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Ok, I haven't used ETS much so I don't know much about it. 2nd, I am attempting with what I know. When all we have is a hammer, everything looks like a nail.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 14:23:43 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551749#M153334</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-17T14:23:43Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551766#M153337</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;&amp;nbsp; &amp;nbsp;here is a SQL solution. I have added some comments so that you can follow the logic/process. Test with a smaller sample, if things go well , scale up.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
/*Your Original sample HAVE*/
data have;
input studyID mth_date $ ed_visits year ;
cards;
1 2011-04 0 2011
1 2011-05 1 2011
1 2012-01 3 2012
2 2011-03 4 2011
3 2011-04 2 2011
3 2011-06 0 2011
3 2013-08 2 2013
;
run;

/*Creating a temp dataset where we extract date numeric values from your char dates in the form
2011-04*/
/*This md=input(compress(mth_date,'-'),yymmn6.) does that */
data temp;
set have;
md=input(compress(mth_date,'-'),yymmn6.);
run;

/*Taking the previous temp table for our look ahead process to get our final want*/

proc sql;
create table want(drop=md) as
select distinct studyID,mth_date ,md, ed_visits, year, sum(t)&amp;gt;=3 as repeat_user
from
(select a.*,ifn(count(a.studyid)=1, a.ed_visits, (intck('month',a.md,b.md)&amp;lt;=12)*(b.ed_visits+a.ed_visits)) as t
from temp a left join temp b
on a.studyid=b.studyid and b.md&amp;gt;a.md
group by a.studyid)
group by studyid
order by studyid,md;
quit;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I used some boolean expressions. In essence the 2 select passes can still be made into one with more boolean games, however my concern is I want us to make it work to achieve a working solution first and once that's done, I will have some fun later.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 15:11:50 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551766#M153337</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-17T15:11:50Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551853#M153383</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok here's the update, i have managed to get the hash version mostly working, but it's missing some people. From what I can tell it looks as if there are a series of 1's and 2's in "ed_visits" it adds them up just fine and makes the appropriate flag. If there is a record with more than 2 it seems to miss it. For example, if someone has 2 visits in 2011-04 and 2 visits in 2011-05 the code works great. If however, the person has 3 visits in 2011-04 (which still counts as a repeat user) it misses them.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm still working on getting the SQL up and running, I have a working code but I think I might have messed something up because it's doing the opposite of the hash, it's catching way more than it should.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts on either of those would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 18:38:30 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551853#M153383</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-17T18:38:30Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551860#M153386</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much for this suggestion. I've managed to get the date value to where it needs to be, and I've been playing with proc expand.&lt;/P&gt;&lt;P&gt;&amp;nbsp;The problem that I'm running into is that proc expand apparently doesn't like it when you have 2 identical id variables (time variables) right after each other and throws up an error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since I have multiple records taken from different subjects on the same date, I can't figure out how to make it work.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;proc sort data=have;
by date;
run; 

proc expand data=have;
out=want
to=month
method=none;
id date;
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;This gives me an "observation with duplicate ID value found" error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any thoughts would be much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks so much&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 19:14:35 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551860#M153386</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-17T19:14:35Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551862#M153387</link>
      <description>&lt;P&gt;As I re-read my original suggestion, its not clear why you have 2 identical ID variables right after each other, and this was not something I envisioned. Explain further how this happens, and please show us a small example.&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 19:16:54 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551862#M153387</guid>
      <dc:creator>PaigeMiller</dc:creator>
      <dc:date>2019-04-17T19:16:54Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551865#M153388</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;&amp;nbsp; &amp;nbsp;Thank your for your patience and feedback. Can you post a more comprehensive sample of your HAVE and the WANT. I have a feeling, I am failing to understand the requirement somewhere.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Objective : To find study id's have 3 or more ed_visits within 12 months ( we'll call them repeat users)&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;My understanding: If interval between "&lt;U&gt;&lt;STRONG&gt;any 2&lt;/STRONG&gt; dates&lt;/U&gt; is &amp;lt;=12", that qualifies. So if month interval between first record of studyid and 3rd record or nth record of studyid&amp;nbsp; is &amp;lt;=12, that still qualifies.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So once we have the dates extracted&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;md=input(compress(mth_date,'-'),yymmn6.);&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here is how the HASH logic works:&lt;/P&gt;
&lt;P&gt;1. Dataset temp with extracted date is sorted by studyid for By group processing&lt;/P&gt;
&lt;P&gt;2. For every observation of By group, the look up happens for all obs for it's equivalent. So if studyid has 3 obs as in the sample, the look up happens 3*3=9 times i.e 1 obs of studyid1 with all 3 obs of studyid 1, then&amp;nbsp;&amp;nbsp;2nd obs of studyid1 with all 3 obs of studyid 1 etc.&lt;/P&gt;
&lt;P&gt;3. Since it is a look ahead(next set of records i.e future dates) the look up(hash table) md variable should be greater than the current md variable of&amp;nbsp; the table from which the look up is taking place.&lt;/P&gt;
&lt;P&gt;4. Should 3 be true, we check whether number of months between the two dates is &amp;lt;=12. If 3 and 4 happen to be true, we sum ed_visit of current +ed_visits of the future(look up table)&lt;/P&gt;
&lt;P&gt;4. The sum is a running total across each by group&amp;nbsp;&lt;/P&gt;
&lt;P&gt;5. At the end of each by group should the cumulative sum is &amp;gt;=3 then that entire group should be flagged as 1 else 0&lt;/P&gt;
&lt;P&gt;6. In instances, where there is only one record for a by group, should the value of ed_visits is &amp;gt;=3 that should also be flagged as 1.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If the above is correct,&amp;nbsp;I think where i perhaps was an idiot is likely this part that I am noticing now, that misses it is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;STRONG&gt;&lt;EM&gt;The logic requires change to--&amp;gt;&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;do rc=h.find() by 0 while(rc=0);
if md&amp;gt;_md and intck('month',_md,md)&amp;lt;=12 then do;
k=sum(ed_visits,_ed_visits);
_k+k;
end;&lt;BR /&gt;rc=h.find_next();&lt;BR /&gt;end;&lt;/PRE&gt;
&lt;P&gt;&lt;STRONG&gt;from the earlier below&lt;/STRONG&gt;&lt;/P&gt;
&lt;PRE&gt;do rc=h.find() by 0 while(rc=0);
if md&amp;gt;_md and intck('month',_md,md)&amp;lt;=12 then k=sum(ed_visits,_ed_visits);
rc=h.find_next();
end;
_k+k;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So the changed full version is&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;
data want;
if _n_=1 then do;
	if 0 then set have;
   dcl hash H (dataset:'have',ordered: "A",multidata:'y') ;
   h.definekey  ("studyID") ;
   h.definedata ("md","ed_visits") ;
   h.definedone () ;
end;
_k=0;
do until(last.studyid);
set have(rename=(md=_md ed_visits=_ed_visits));
by studyID;
do rc=h.find() by 0 while(rc=0);
if md&amp;gt;_md and intck('month',_md,md)&amp;lt;=12 then do;
k=sum(ed_visits,_ed_visits);
_k+k;
end;
rc=h.find_next();
end;
end;
repeat_user=first.studyid and last.studyid and _ed_visits&amp;gt;=3  or k&amp;gt;=3 ;
do until(last.studyid);
set have;
by studyID;
output;
end;
keep studyid mth_date ed_visits year repeat_user;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Let me know. Sorry and Thank you for your patience.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 19:29:00 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551865#M153388</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-17T19:29:00Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551940#M153414</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp; and&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/10892"&gt;@PaigeMiller&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;First off, I really appreciate the time you are spending on this. It's really helping me learn a lot.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly,&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;you have no need to apologize, you are&amp;nbsp; both doing me a huge service helping me out on this, and anyone who would be impatient when someone is volunteering to help them probably doesn't deserve your help. Thank you.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Since things have changed a bit after a day of working on this, I thought a general update and summary of where we are at would be helpful.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;1. I've managed to convert the date variables in the dataset to SAS dates, so my dataset now looks something like this:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input studyID date :anydtdte10. ed_visits year ;
cards;
1 2011-04 0 2011
1 2011-05 1 2011
1 2012-01 3 2012
1 2012-04 0 2012
1 2013-05 2 2013
1 2013-06 0 2013
2 2011-03 4 2011
3 2011-04 2 2011
3 2011-06 0 2011
3 2013-08 2 2013
4 2011-04 1 2011
4 2012-05 1 2012
4 2013-06 1 2013
4 2014-07 1 2014
5 2011-03 0 2011
5 2012-05 0 2012
5 2013-08 4 2013
5 2014-02 0 2013
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Ideally, I would like to end up with a dataset that looks like this&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data want;
input studyID date :anydtdte10. ed_visits year repeat_user ;
cards;
1 2011-04 0 2011 1
1 2011-05 1 2011 1
1 2012-01 2 2012 1
1 2012-04 0 2012 1 
1 2013-05 2 2013 1
1 2013-06 0 2013 1
2 2011-03 4 2011 1
3 2011-04 2 2011 0
3 2011-06 0 2011 0
3 2013-08 2 2013 0
4 2011-04 1 2011 0
4 2012-05 1 2012 0
4 2013-06 1 2013 0
4 2014-07 1 2014 0
5 2011-03 0 2011 1
5 2012-05 0 2012 1
5 2013-08 4 2013 1
5 2014-02 0 2013 1
run;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;where 1 indicates a repeat user.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Our criteria for a repeat user is 3 or more ed visits within a 12 month period.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So in this case:&amp;nbsp;&lt;/P&gt;&lt;P&gt;#1 is a repeat user because they had 3 visits between 2011-05 and 2012-01 (less than 12 months apart). The 2 visits in 2013-05 don't affect anything&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#2 is a repeat user, because even though we only have one month of data for them, they had 4 visits in the month&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#3 is not a repeat user because even though they had 4 visits, 2 were in 2011 and 2 were in 2013 (more than 12 months apart)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#4 is not a repeat user because they only had 1 visit in each year, with more than 12 months between them.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;#5 is a repeat user for the same reason as #2, we just have more data because they were in the study longer.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thus far we've tried:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Proc expand - looked promising but ran into trouble because of overlapping dates. for example, both #1 and #2 and #4 have records for 2011-04. proc throws up an error because of the duplicate values in the ID field (date)&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;'s hash method - This one feel like we're close, but while it does a good job of identifying cases like&amp;nbsp; #1, it misses cases like #2 and #5 - I've tried the updated code and get the same results as before.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;'s sql method - This one is also close, but has the opposite problem of the Hash method, it's capturing many records that have less than three ed visits within 12 months, I haven't spotted any particular pattern yet, but I'll let you know if I find anything.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;and that's where we are at. I'm going to keep playing with the code I have to see if I can't figure out where things are going wrong, but I hope this clarifies things. Any further insights would be very much appreciated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you both so much&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 17 Apr 2019 23:24:28 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551940#M153414</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-17T23:24:28Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551948#M153418</link>
      <description>&lt;P&gt;Hi and Good evening&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/154458"&gt;@righcoastmike&lt;/a&gt;&amp;nbsp; &amp;nbsp;A&amp;nbsp; silly change that i missed to make&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The k&amp;gt;3 below&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;repeat_user&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;studyid and last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;studyid and _ed_visits&lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;  or k&lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;should have been&amp;nbsp; _k&amp;gt;3 with a prefix _ underscore coz that's the accumlating var&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;So I tested with the changed below&lt;/P&gt;
&lt;LI-CODE lang="sas"&gt;repeat_user&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;first&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;studyid and last&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;studyid and _ed_visits&lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt;  or _k&lt;SPAN class="token operator"&gt;&amp;gt;=&lt;/SPAN&gt;&lt;SPAN class="token number"&gt;3&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Here --&amp;gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;/*Again I converted to SAS dates, this is no big deal*/
data have;
input studyID date $ ed_visits year ;
md=input(compress(date,'-'),yymmn6.); /*notice here the converted SAS date variable*/
format md date9.;
cards;
1 2011-04 0 2011
1 2011-05 1 2011
1 2012-01 3 2012
1 2012-04 0 2012
1 2013-05 2 2013
1 2013-06 0 2013
2 2011-03 4 2011
3 2011-04 2 2011
3 2011-06 0 2011
3 2013-08 2 2013
4 2011-04 1 2011
4 2012-05 1 2012
4 2013-06 1 2013
4 2014-07 1 2014
5 2011-03 0 2011
5 2012-05 0 2012
5 2013-08 4 2013
5 2014-02 0 2013
run;


/*the same code with _k&amp;gt;3 lol hahaha*/
data want;
if _n_=1 then do;
	if 0 then set have;
   dcl hash H (dataset:'have',ordered: "A",multidata:'y') ;
   h.definekey  ("studyID") ;
   h.definedata ("md","ed_visits") ;
   h.definedone () ;
end;
_k=0;
do until(last.studyid);
set have(rename=(md=_md ed_visits=_ed_visits));
by studyID;
do rc=h.find() by 0 while(rc=0);
if md&amp;gt;_md and intck('month',_md,md)&amp;lt;=12 then do;
k=sum(ed_visits,_ed_visits);
_k+k;
end;
rc=h.find_next();
end;
end;
repeat_user=first.studyid and last.studyid and _ed_visits&amp;gt;=3  or _k&amp;gt;=3 ;
do until(last.studyid);
set have;
by studyID;
output;
end;
keep studyid date md ed_visits year repeat_user;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Proc print noobs;run;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here are the test results;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;study repeat_&lt;BR /&gt;ID date ed_visits year md user&lt;/P&gt;
&lt;P&gt;1 2011-04 0 2011 01APR2011 1&lt;BR /&gt;1 2011-05 1 2011 01MAY2011 1&lt;BR /&gt;1 2012-01 3 2012 01JAN2012 1&lt;BR /&gt;1 2012-04 0 2012 01APR2012 1&lt;BR /&gt;1 2013-05 2 2013 01MAY2013 1&lt;BR /&gt;1 2013-06 0 2013 01JUN2013 1&lt;BR /&gt;2 2011-03 4 2011 01MAR2011 1&lt;BR /&gt;3 2011-04 2 2011 01APR2011 0&lt;BR /&gt;3 2011-06 0 2011 01JUN2011 0&lt;BR /&gt;3 2013-08 2 2013 01AUG2013 0&lt;BR /&gt;4 2011-04 1 2011 01APR2011 0&lt;BR /&gt;4 2012-05 1 2012 01MAY2012 0&lt;BR /&gt;4 2013-06 1 2013 01JUN2013 0&lt;BR /&gt;4 2014-07 1 2014 01JUL2014 0&lt;BR /&gt;5 2011-03 0 2011 01MAR2011 1&lt;BR /&gt;5 2012-05 0 2012 01MAY2012 1&lt;BR /&gt;5 2013-08 4 2013 01AUG2013 1&lt;BR /&gt;5 2014-02 0 2013 01FEB2014 1&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Please let me know at your earliest convenience.&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 00:37:48 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551948#M153418</guid>
      <dc:creator>novinosrin</dc:creator>
      <dc:date>2019-04-18T00:37:48Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551956#M153419</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/138205"&gt;@novinosrin&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Ok we're getting somewhere now, the latest code made it so the hash and the sql are producing the same results, they aren't quite correct but at least it could help to identify the problem. Here is a complete example of a study id that has been misidentified as a 1 when it should be a zero:&amp;nbsp;&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; have&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt; studyID &lt;SPAN class="token function"&gt;date&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;$&lt;/SPAN&gt; ed_visits &lt;SPAN class="token function"&gt;year&lt;/SPAN&gt; &lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
md&lt;SPAN class="token operator"&gt;=&lt;/SPAN&gt;&lt;SPAN class="token keyword"&gt;input&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;compress&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;(&lt;/SPAN&gt;&lt;SPAN class="token function"&gt;date&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;&lt;SPAN class="token string"&gt;'-'&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;)&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;,&lt;/SPAN&gt;yymmn6&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 comment"&gt;/*notice here the converted SAS date variable*/&lt;/SPAN&gt;
&lt;SPAN class="token procnames"&gt;format&lt;/SPAN&gt; md date9&lt;SPAN class="token punctuation"&gt;.&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;;&lt;/SPAN&gt;
&lt;SPAN class="token keyword"&gt;cards&lt;/SPAN&gt;&lt;SPAN class="token punctuation"&gt;; &lt;BR /&gt;&lt;/SPAN&gt;1 2011-04 0 2011&lt;BR /&gt;1 2011-05 0 2011&lt;BR /&gt;1 2011-06 0 2011&lt;BR /&gt;1 2011-07 0 2011&lt;BR /&gt;1 2011-08 0 2011&lt;BR /&gt;1 2011-09 0 2011&lt;BR /&gt;1 2011-10 0 2011&lt;BR /&gt;1 2011-11 0 2011&lt;BR /&gt;1 2011-12 0 2011&lt;BR /&gt;1 2012-01 0 2012&lt;BR /&gt;1 2012-02 0 2012&lt;BR /&gt;1 2012-03 2 2012&lt;BR /&gt;1 2012-04 0 2012&lt;BR /&gt;1 2012-05 0 2012&lt;BR /&gt;1 2012-06 0 2012&lt;BR /&gt;1 2012-07 0 2012&lt;BR /&gt;1 2012-08 0 2012&lt;BR /&gt;1 2012-09 0 2012&lt;BR /&gt;1 2012-10 0 2012&lt;BR /&gt;1 2012-11 0 2012&lt;BR /&gt;1 2012-12 0 2012&lt;BR /&gt;1 2013-01 0 2013&lt;BR /&gt;1 2013-02 0 2013&lt;BR /&gt;1 2013-03 0 2013&lt;BR /&gt;1 2013-04 0 2013&lt;BR /&gt;1 2013-05 0 2013&lt;BR /&gt;1 2013-06 0 2013 &lt;BR /&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;&amp;nbsp; I ran the code on just this studyid alone, and the misclassification persists. The only thing I can think of is that the fact that there are 27 records associated with the one studyid is throwing it off.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thoughts?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Mike&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Apr 2019 01:39:18 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551956#M153419</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-18T01:39:18Z</dc:date>
    </item>
    <item>
      <title>Re: Trying to create a new binary variable based on a rolling time window</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551957#M153420</link>
      <description>&lt;P&gt;sorry for the weird code, I'm not sure what happened there.&amp;nbsp;&lt;/P&gt;&lt;P&gt;here's a better version.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;mike&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data have;
input studyID date $ ed_visits year ;
md=input(compress(date,'-'),yymmn6.); /*notice here the converted SAS date variable*/
format md date9.;
cards; 
1 2011-04 0 2011
1 2011-05 0 2011
1 2011-06 0 2011
1 2011-07 0 2011
1 2011-08 0 2011
1 2011-09 0 2011
1 2011-10 0 2011
1 2011-11 0 2011
1 2011-12 0 2011
1 2012-01 0 2012
1 2012-02 0 2012
1 2012-03 2 2012
1 2012-04 0 2012
1 2012-05 0 2012
1 2012-06 0 2012
1 2012-07 0 2012
1 2012-08 0 2012
1 2012-09 0 2012
1 2012-10 0 2012
1 2012-11 0 2012
1 2012-12 0 2012
1 2013-01 0 2013
1 2013-02 0 2013
1 2013-03 0 2013
1 2013-04 0 2013
1 2013-05 0 2013
1 2013-06 0 2013 
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Thu, 18 Apr 2019 01:41:22 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Trying-to-create-a-new-binary-variable-based-on-a-rolling-time/m-p/551957#M153420</guid>
      <dc:creator>righcoastmike</dc:creator>
      <dc:date>2019-04-18T01:41:22Z</dc:date>
    </item>
  </channel>
</rss>

