datetime - SAS Given a start & end date I need to know the dates of each 30 day period AFTER the first 35 days -


i am given 2 dates, start date , end date.

i know date of first 35 day period, each subsequent 30 day period.

i have;

start       end 22-jun-15   22-oct-15 9-jan-15    15-may-15 

i want;

start       end         tik1        tik2        tik3        tik4 22-jun-15   22-oct-15   27-jul-15   26-aug-15   25-sep-15    9-jan-15    15-may-15   13-feb-15   15-mar-15   14-apr-15   14-may-15 

i fine dates calculations real issue creating variable , incrementing name. decided include whole problem because thought might easier explain in context.

you can solve problem via following logic:

1) determining number of columns added.

2) calculating values columns basis requirement

data test; input start end; informat start date9. end date9.; format start date9. end date9.; datalines; 22-jun-15 22-oct-15 09-jan-15 15-may-15 ; run;  /*******determining number of columns*******/ data noc_cal; set test; no_of_col = floor((end-start)/30); run; proc sql; select max(no_of_col) into: number_of_columns noc_cal; run;  /*******making array 1st iteration(tik1) increased 35days whereas others incremented 30days*******/ data test1; set test; array tik tik1-tik%sysfunc(compress(&number_of_columns.)); format tik: date9.; tik1 = intnx('days',start,35); i= 2 %sysfunc(compress(&number_of_columns.)); tik[i]= intnx('days',tik[i-1],30); if tik[i] > end tik[i]=.; end;  drop i; run; 

alternate way (incase dont want use proc sql)

data test; input start end; informat start date9. end date9.; format start date9. end date9.; datalines; 22-jun-15 22-oct-15 09-jan-15 15-may-15 ; run;  /*******determining number of columns*******/ data noc_cal; set test; no_of_col = floor((end-start)/30); run;  proc sort data=noc_cal; no_of_col; run;  data _null_; set noc_cal; no_of_col; if last.no_of_col; call symputx('number_of_columns',no_of_col); run;  /*******making array 1st iteration(tik1) increased 35days whereas others incremented 30days*******/ data test1; set test; array tik tik1-tik%sysfunc(compress(&number_of_columns.)); format tik: date9.; tik1 = intnx('days',start,35); i= 2 %sysfunc(compress(&number_of_columns.)); tik[i]= intnx('days',tik[i-1],30); if tik[i] > end tik[i]=.; end;  drop i; run; 

my output:

> **start   |end        |tik1     | tik2     |tik3     |tik4** > 22jun2015 |22oct2015  |27jul2015| 26aug2015|25sep2015|     > 09jan2015 |15may2015  |13feb2015| 15mar2015|14apr2015|14may2015 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -