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 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

 

1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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;
      

View solution in original post

1 REPLY 1
ballardw
Super User

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;
      

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
  • 1 reply
  • 1707 views
  • 3 likes
  • 2 in conversation