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;
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: