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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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