No need for ETS. Simple data step is sufficient to get an elegant solution. Change Date into a Number by using the MDY() function. Use one array for 2014(say, k_14[ ]) and anther array for average of 2012 & 13 (say, k_13[ ]). In double DoW-loops, read observations from the two data sets by BY GROUP (by CODE). Then merge the two arrays into one and output the results. data one(drop=date dd mm); input code $3. @9 date $5. count; mm = substr(date,1,2); dd = substr(date, 4); ndate = mdy(mm,dd, 2014); datalines; 1X1 07/01 1 1X1 07/03 1 1X1 07/06 0 2Y3 . 0 3J8 07/02 1 3J8 07/03 0 ; run; data two(drop=date dd mm); input code $3. @9 date $5. count; mm = substr(date,1,2); dd = substr(date, 4); ndate = mdy(mm,dd, 2014); datalines; 1X1 07/01 0 1X1 07/02 1 1X1 07/04 0 2Y3 07/01 1 3J8 . 0 ; run; data want(rename = (i = Date)); array k_14[19905:19911] _temporary_; array k_13[19905:19911] _temporary_; do until(last.code); set one; by code; if not missing(ndate) then k_14[ndate] = count; end; do until(last.code); set two; by code; if not missing(ndate) then k_13[ndate] = count; end; do i = lbound(k_14) to hbound(k_14); count_14 = ifN(k_14 > 0, k_14, 0); count_13 = ifN(k_13 > 0, k_13, 0); output; end; call missing(of k_14 , of k_13 ); keep code i count_14 count_13; format i date5.; run;
... View more