BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
data a;
  input patientid  start : mmddyy10.  end : mmddyy10. ;
  format   start end  mmddyy10.;
datalines;
1  1/1/2006 4/1/2006
 
2   1/2/2006 12/2/2007;
run;

I have data that contains one row per patient with start and end date. I want to create 30 days interval following the start date until the end date. The output would be : 

 

1 1/1/2006 31/12006 

1 31/1/2006  3/2/2006 

1 3/2/2006   4/1/2006

2 1/2/2006  2/1/2006

 

and so on 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
novinosrin
Tourmaline | Level 20
data a;
  input patientid  start : mmddyy10.  end : mmddyy10. ;
  format   start end  date9.;
datalines;
1  1/1/2006 4/1/2006
2   1/2/2006 12/2/2007
;
run;


data want;
set a(rename=end=_end);
do while(start<_end);
end=intnx('days',start,30);
output;
start=end;
end;
format start end mmddyy10.;
drop _:;
run;

View solution in original post

4 REPLIES 4
novinosrin
Tourmaline | Level 20
data a;
  input patientid  start : mmddyy10.  end : mmddyy10. ;
  format   start end  date9.;
datalines;
1  1/1/2006 4/1/2006
2   1/2/2006 12/2/2007
;
run;


data want;
set a(rename=end=_end);
do while(start<_end);
end=intnx('days',start,30);
output;
start=end;
end;
format start end mmddyy10.;
drop _:;
run;
lillymaginta
Lapis Lazuli | Level 10

Thank you! 

Astounding
PROC Star

Here's one way to approach the problem.  It's untested code, so you will have to verify whether the results are correct:

 

data want;

set have;

original_end = end;

do while (end - start > 30);

   end = start + 30;

   output;

   start = end ;

   end = original_end;

end;

output;

drop original_end;

run;

 

Notice how it's a little harder to read because END is both a SAS statement and a variable name.  If it's within your control, try to avoid that situation.

Kurt_Bremser
Super User

Please be consistent with your date formatting. I suggest to use the yymmddd10. format, as that is ISO-compliant.

As it is, some of your dates in then output seem to be DMY order, while others are MDY.

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1650 views
  • 4 likes
  • 4 in conversation