<?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: Only Keep People who Continuously Registered as Member in SAS Programming</title>
    <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772351#M245231</link>
    <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; impressive, would this even work, if begin and end date are not in the same year?&lt;/P&gt;</description>
    <pubDate>Wed, 06 Oct 2021 05:53:07 GMT</pubDate>
    <dc:creator>andreas_lds</dc:creator>
    <dc:date>2021-10-06T05:53:07Z</dc:date>
    <item>
      <title>Only Keep People who Registered as Member between two dates</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772307#M245214</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I would like to restrict a group of people who is continuously as a member between start and end date.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My data looks like below:&lt;/P&gt;&lt;P&gt;ID&amp;nbsp; &amp;nbsp;StartDate&amp;nbsp; &amp;nbsp; &amp;nbsp;EndDate&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;3/19/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; 6/01/2019&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp;7/7/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/21/2019&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp;3/6/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;9/01/2019&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Registration data is:&lt;/P&gt;&lt;P&gt;member_id 01/2019&amp;nbsp; 02/2019 03/2019&amp;nbsp; &amp;nbsp;...&lt;/P&gt;&lt;P&gt;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;1&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 1&lt;/P&gt;&lt;P&gt;2&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 0&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;so the output data will only keep record '1&amp;nbsp; &amp;nbsp; &amp;nbsp;7/7/2019&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; 8/21/2019' since person1 is a member between start and end dates.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any recommendation will be appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you!&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 21:46:10 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772307#M245214</guid>
      <dc:creator>huhuhu</dc:creator>
      <dc:date>2021-10-06T21:46:10Z</dc:date>
    </item>
    <item>
      <title>Re: Only Keep People who Continuously Registered as Member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772333#M245223</link>
      <description>&lt;P&gt;Here is one approach. It might be easier to transpose your registration data, especially if start and end dates cover multiple years.&amp;nbsp; I have assumed below that part month registrations should be included.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data member ;
	infile cards dlm=',' ;
	input id StartDate:mmddyy10. EndDate:mmddyy10. ;

	StartMonth=intnx('MONTH',StartDate,0,'B') ;
	EndMonth=intnx('MONTH',EndDate,0,'B') ;

	format StartDate EndDate StartMonth EndMonth ddmmyy10. ;
cards ;
1,3/19/2018,6/01/2018
1,7/7/2019,8/21/2019
2,3/6/2019,9/01/2019
;
run ;

data registration ;
	infile cards dlm=',' ;
	input person_id year jan feb mar apr may jun jul aug sep oct nov dec ;
cards ;
1,2018,0,0,0,1,1,0,0,0,0,0,0,1
1,2019,1,1,1,1,1,1,1,1,1,1,1,1
2,2018,1,1,0,0,1,1,1,1,1,1,1,1
2,2019,1,1,1,1,1,1,0,0,0,0,0,0
;
run;

data registrationTransposed ;
	set registration ;
	array mon(12) jan feb mar apr may jun jul aug sep oct nov dec ;
	do i=1 to 12 ;
		date=mdy(i,1,year) ;
		Flag=mon(i) ;
		output ;
	end ;
	keep person_id date flag ;
	format  date monyy7. ;
run ;

proc sql ;
	create table want as select distinct
 	m.ID
	,m.StartDate
	,m.EndDate

	from member as m
	inner join
	registrationTransposed as r

	on 
	m.id=r.Person_ID
	and r.Date between m.StartMonth and m.EndMonth

	group by 1,2,3

	having sum(Flag)=intck('MONTH',m.StartMonth,m.EndMonth)+1 ;
;
quit ;&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 02:42:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772333#M245223</guid>
      <dc:creator>seemiyah</dc:creator>
      <dc:date>2021-10-06T02:42:07Z</dc:date>
    </item>
    <item>
      <title>Re: Only Keep People who Continuously Registered as Member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772334#M245224</link>
      <description>&lt;P&gt;You can do this in a single DATA step by (1) reading in the registration months for a given ID, (2) populating a two-way registration history array indexed by year for the row and month for the column, (3) reading in the start_end_spans for the same ID and checking those spans against the registration history:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data start_end_spans ;
  input id StartDate:mmddyy10. EndDate:mmddyy10. ;
  format StartDate EndDate date9. ;
cards ;
1 3/19/2018 6/01/2018
1 7/7/2019  8/21/2019
2 3/6/2019  9/01/2019
run;

data registration_months;
  input id year jan feb mar apr may jun jul aug sep oct nov dec ;
cards ;
1 2018 0 0 0 1 1 0 0 0 0 0 0 1
1 2019 1 1 1 1 1 1 1 1 1 1 1 1
2 2018 1 1 0 0 1 1 1 1 1 1 1 1
2 2019 1 1 1 1 1 1 0 0 0 0 0 0
run;

data want (keep=id startdate enddate);
  set registration_months (in=inreg) start_end_spans (in=in_spans);
  by id;

  array reg_history{2018:2019,1:12} _temporary_;
  if first.id then call missing(of reg_history{*});

  array reg_months {12} jan--dec ;
  if inreg then do m=1 to 12;
    reg_history{year,m}=reg_months{m};
  end;

  if in_spans;
  missing_month=0;
  date=startdate;
  do until (date&amp;gt;enddate or missing_month=1);
    if reg_history{year(date),month(date)}^=1 then missing_month=1;
    date=intnx('month',date,1,'b');
  end;
  if missing_month=0;
run;&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Just be sure to declare the possible span of years ( I used 2018 through 2019 above) in the reg_history array statement.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 04:01:53 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772334#M245224</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-10-06T04:01:53Z</dc:date>
    </item>
    <item>
      <title>Re: Only Keep People who Continuously Registered as Member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772351#M245231</link>
      <description>&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; impressive, would this even work, if begin and end date are not in the same year?&lt;/P&gt;</description>
      <pubDate>Wed, 06 Oct 2021 05:53:07 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772351#M245231</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-06T05:53:07Z</dc:date>
    </item>
    <item>
      <title>Re: Only Keep People who Continuously Registered as Member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772355#M245233</link>
      <description>&lt;P&gt;Here is another solution picking up the idea of transposing mentioned by &lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/157852"&gt;@seemiyah&lt;/a&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-sas"&gt;data reg_months_transformed;
   set registration_months;
   
   length date 8;
   format date date9.;
   
   array months[12] jan feb mar apr may jun jul aug sep oct nov dec;
   
   do i = 1 to 12;
      if months[i] = 1 then do;
         date = mdy(i, 1, year);
         output;
      end;
   end;
   
   drop year jan feb mar apr may jun jul aug sep oct nov dec i;
run;

data want;
   if 0 then set work.reg_months_transformed;
   set start_end_spans;
   
   if _n_ = 1 then do;
      declare hash h(dataset: 'work.reg_months_transformed');
      h.defineKey('id', 'date');
      h.defineDone();
   end;
   
   s = intnx('month', StartDate, 0, 'b');
   e = intnx('month', EndDate, 0, 'b');
   complete = 1;
   
   do i = 0 to intck('month', s, e) ;
      date = intnx('month', StartDate, i, 'b');
      complete = complete and (h.check() = 0);
   end;
   
   if complete;
   
   drop e i s date complete;
run;&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Oct 2021 06:27:44 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772355#M245233</guid>
      <dc:creator>andreas_lds</dc:creator>
      <dc:date>2021-10-06T06:27:44Z</dc:date>
    </item>
    <item>
      <title>Re: Only Keep People who Continuously Registered as Member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772356#M245234</link>
      <description>&lt;BLOCKQUOTE&gt;&lt;HR /&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/15475"&gt;@andreas_lds&lt;/a&gt;&amp;nbsp;wrote:&lt;BR /&gt;
&lt;P&gt;&lt;a href="https://communities.sas.com/t5/user/viewprofilepage/user-id/31461"&gt;@mkeintz&lt;/a&gt; impressive, would this even work, if begin and end date are not in the same year?&lt;/P&gt;
&lt;HR /&gt;&lt;/BLOCKQUOTE&gt;
&lt;P&gt;Yes, because:&lt;/P&gt;
&lt;OL&gt;
&lt;LI&gt;The registration history covers multiple years, so the available history is complete by the time a start_end_span observation is read..&lt;/LI&gt;
&lt;LI&gt;The DO UNTIL uses the intnx function to advance from startdate to enddate by 1 month increments while confirming registration status for the corresponding year/month.&amp;nbsp; The intnx function crosses year boundaries seamlessly.&lt;/LI&gt;
&lt;/OL&gt;</description>
      <pubDate>Wed, 06 Oct 2021 06:36:06 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772356#M245234</guid>
      <dc:creator>mkeintz</dc:creator>
      <dc:date>2021-10-06T06:36:06Z</dc:date>
    </item>
    <item>
      <title>Re: Only Keep People who Continuously Registered as Member</title>
      <link>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772411#M245260</link>
      <description>&lt;PRE&gt;data start_end_spans ;
  input id StartDate:mmddyy10. EndDate:mmddyy10. ;
  format StartDate EndDate date9. ;
cards ;
1 3/19/2018 6/01/2018
1 7/7/2019  8/21/2019
2 3/6/2019  9/01/2019
;
run;


data want;
   set start_end_spans ;
      year=year(StartDate);
   
   array months[12] jan feb mar apr may jun jul aug sep oct nov dec;
   do i=1 to dim(months);
    months[i] = 0;
   end; 
   do i = StartDate to EndDate;
     if month(i) ne m then  months[month(i)]=1;
	 m= month(i);
   end;
   drop m i;
run;&lt;/PRE&gt;</description>
      <pubDate>Wed, 06 Oct 2021 12:31:01 GMT</pubDate>
      <guid>https://communities.sas.com/t5/SAS-Programming/Only-Keep-People-who-Registered-as-Member-between-two-dates/m-p/772411#M245260</guid>
      <dc:creator>Ksharp</dc:creator>
      <dc:date>2021-10-06T12:31:01Z</dc:date>
    </item>
  </channel>
</rss>

