BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
mosadoluwa
Calcite | Level 5

Hello, 

I'm trying to combine the days of monthly enrollment for patients into an enrollment period.

Here is what I have:

ID Start End Enrol_Period

001 01/01/2015 01/31/2015 1

001 02/01/2015 02/28/2015 1

001 05/01/2015 05/31/2015 2

001 06/01/2015 06/30/2015 2

001 07/01/2015 07/31/2015 2

001 08/01/2015 08/31/2015 2

Similar format for other patients

 

Here is what I want:

001 01/01/2015 02/28/2015 1

001 05/01/2015 08/31/2015 2

 

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20
data have;
input ID $ (Start End)(:mmddyy10.) Enrol_Period;
format Start End mmddyy10.;
datalines;
001 01/01/2015 01/31/2015 1
001 02/01/2015 02/28/2015 1
001 05/01/2015 05/31/2015 2
001 06/01/2015 06/30/2015 2
001 07/01/2015 07/31/2015 2
001 08/01/2015 08/31/2015 2
;

data want(keep=ID Start End Enrol_Period);
   set have;
   by Enrol_Period;
   if first.Enrol_Period then s=Start;
   if last.Enrol_Period then do;
      Start=s;
      output;
   end;
   retain s;
run;

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20
data have;
input ID $ (Start End)(:mmddyy10.) Enrol_Period;
format Start End mmddyy10.;
datalines;
001 01/01/2015 01/31/2015 1
001 02/01/2015 02/28/2015 1
001 05/01/2015 05/31/2015 2
001 06/01/2015 06/30/2015 2
001 07/01/2015 07/31/2015 2
001 08/01/2015 08/31/2015 2
;

data want(keep=ID Start End Enrol_Period);
   set have;
   by Enrol_Period;
   if first.Enrol_Period then s=Start;
   if last.Enrol_Period then do;
      Start=s;
      output;
   end;
   retain s;
run;
novinosrin
Tourmaline | Level 20

data have;
input ID $ (Start End)(:mmddyy10.) Enrol_Period;
format Start End mmddyy10.;
datalines;
001 01/01/2015 01/31/2015 1
001 02/01/2015 02/28/2015 1
001 05/01/2015 05/31/2015 2
001 06/01/2015 06/30/2015 2
001 07/01/2015 07/31/2015 2
001 08/01/2015 08/31/2015 2
;


proc sql;
create table want as
select id, min(start) as start format=mmddyy10.,max(end) as end format=mmddyy10.,Enrol_Period
from have
group by id, Enrol_Period;
quit;

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 504 views
  • 0 likes
  • 3 in conversation