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

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