Hello, You can first fill-in the missing series and afterwards concatenate the datasets: data dataset1 (drop=date); input Code $ Date $ Count_2014; if missing(Date)=0 then date_num=mdy(input(substr(date,1,2),3.),input(substr(date,4,2),3.),2014); format date_num date7.; datalines; 1X1 07/01 1 1X1 07/03 1 1X1 07/06 0 2Y3 . 0 3J8 07/02 1 3J8 07/03 0 4J8 07/02 1 4J8 07/07 0 ; run; data dataset2 (drop=date); input Code $ Date $ Count_2012_2013; if missing(Date)=0 then date_num=mdy(input(substr(date,1,2),3.),input(substr(date,4,2),3.),2014); format date_num date7.; datalines; 1X1 07/01 0 1X1 07/02 1 1X1 07/04 0 2Y3 07/01 1 3J8 . 0 4J8 07/07 0 ; run; data have1; format date date7.; set dataset1; by Code; retain date; if first.Code then date="01JUL2014"d; do i=date to "07JUL2014"d while (date_num ne date); Observed_Count_2014=0; output; date+1; ; end; if date_num=date then do;Observed_Count_2014=count_2014;output;date+1;end; if last.Code and date_num not in(.,"07JUL2014"d) and date le "07JUL2014"d then do; do until(date="08JUL2014"d) ; Observed_Count_2014=0; output; date+1; end; end; keep code date Observed_Count_2014; run; data have2; format date date7.; set dataset2; by Code; retain date; if first.Code then date="01JUL2014"d; do i=date to "07JUL2014"d while (date_num ne date); Observed_Count_2012_2013=0; output; date+1; ; end; if date_num=date then do;Observed_Count_2012_2013=count_2012_2013;output;date+1;end; if last.Code and date_num not in(.,"07JUL2014"d) and date le "07JUL2014"d then do; do until(date="08JUL2014"d) ; Observed_Count_2012_2013=0; output; date+1; end; end; keep code date Observed_Count_2012_2013; run; proc sql; create table want as select h1.code,h1.date,Observed_Count_2014,Observed_Count_2012_2013 from have1 as h1 inner join have2 as h2 on h1.code=h2.code and h1.date=h2.date; quit;
... View more