Here is a solution that doesn't involve a DOW loop: proc format ; value formula low-15=0 16-40=1 41-70=2 71-100=3 101-140=4 141-175=5 176-225=6 226-300=7 301-high=8 ; run; data have; input ID Email $ type $ edate mmddyy10. ; format edate mmddyy10.; datalines; 1 1 rdate 05/20/2015 1 2 rdate 05/21/2015 1 3 Sdate 10/05/2015 1 4 Sdate 11/09/2015 1 5 Sdate 12/11/2015 2 1 rdate 06/21/2015 2 2 rdate 07/05/2015 2 3 rdate 07/09/2015 2 4 Sdate 06/21/2016 2 5 Sdate 07/05/2016 2 6 Sdate 07/09/2016 ; data want(keep=id newEmail type edate rename=newEmail=Email); retain lastRdate; set have; by id type notsorted; if first.id then do; call missing(lastrdate,firstSdate); newEmail = 0; end; if type="rdate" and last.type then lastRdate = edate; if type="Sdate" and first.type and not missing(lastRdate) then do; firstSdate = edate; nbDates = input(put(intck("DAY",lastRdate,firstSdate),formula.),best.); dayStep = ceil(intck("DAY",lastRdate,firstSdate) / (nbDates+1)); type = "Formula"; do i = 1 to nbDates; edate = intnx('DAY', lastRdate, i*dayStep); newEmail + 1; output; end; type = "Sdate"; edate = firstSdate; end; newEmail + 1; output; run; PG
... View more