data test;
input id$2. start end ;
attrib start format =date9. informat=date9.;
attrib end format =date9. informat=date9.;
datalines;
1 01OCT2014 14JUN2015
1 01OCT2015 14NOV2015
2 18FEB2015 30APR2015;
run;
I have the above data. The max time between the start and the end date is 270 days.
I want to divide the periods into intervals:
period1: 0-90
Period2: 91-180
Period3: 181-270, all would be calculated from the start date.
Output
id start end period
1 01OCT2014 30DEC2014 1
1 30DEC2014 30MAR2015 2
1 30MAR2015 14JUN2015 3
1 01OCT2015 14NOV2015 1
2 18FEB2015 30APR2015 1
This seems to work for the example data:
data test; input id$2. start end ; attrib start format =date9. informat=date9.; attrib end format =date9. informat=date9.; datalines; 1 01OCT2014 14JUN2015 1 01OCT2015 14NOV2015 2 18FEB2015 30APR2015 ; run; data want; set test; period=0; tend = end; do start = start to end by 90; period= period+1; end= intnx('day',start,90); if end>tend then end=tend; output; end; drop tend; run;
This seems to work for the example data:
data test; input id$2. start end ; attrib start format =date9. informat=date9.; attrib end format =date9. informat=date9.; datalines; 1 01OCT2014 14JUN2015 1 01OCT2015 14NOV2015 2 18FEB2015 30APR2015 ; run; data want; set test; period=0; tend = end; do start = start to end by 90; period= period+1; end= intnx('day',start,90); if end>tend then end=tend; output; end; drop tend; run;
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!
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.
Ready to level-up your skills? Choose your own adventure.