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;
      

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