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

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 1684 views
  • 4 likes
  • 4 in conversation