data temp;
input year id price;
DATALINES;
1998 1 10
1999 1 12
2000 1 11.5
1998 2 11
1999 2 11.5
2000 3 12
;
run;
proc sort data=temp out=missing;
by year id;
run;
data missing;
set missing;
price=.;
do year=1995 to 1997;
if year<=1997 then output;
end;
run;
proc sort data=missing nodupkey;
by id year;
proc sort data=temp;
by id year;
/*merge have and the expanded missing*/
data want;
merge missing (in=ina) temp (in=inb);
by id year;
if inb or (ina and not inb);
run;作者: shiyiming 时间: 2013-1-4 02:56 标题: Re: 如何补充数据 [code:1mw391v3]data a;
input year id price;
yi=catx('_',year,id);
cards;
1998 1 10
1999 1 12
2000 1 11.5
1998 2 11
1999 2 11.5
2000 2 12
;
data b;
do id=1 to 2;
do year=1995 to 2005;
yi=catx('_',year,id);
output;
end;
end;
run;
proc sql;
create table ab(drop=yi) as
select d1.*, d2.price from b d1 left join a d2
on d1.yi=d2.yi
order by id,year;
quit;[/code:1mw391v3]