最笨最容易想到的,创建一个数据集再datastep merge.
你的数据第一列是日期,我想可以用time series补齐.
data stock;
input date date9. stock $ price;
datalines;
01JUN2010 A 10.1
02JUN2010 A 10.2
04JUN2010 A 11.1
01JUN2010 B 45.1
02JUN2010 B 43.2
03JUN2010 B 42.1
01JUN2010 C 24.1
03JUN2010 C 23.2
04JUN2010 C 22.1
;
run;
proc sort data = stock;
by stock date;
run;
proc timeseries data=stock out=want;
id date interval=day accumulate=total setmissing = missing;
var price;
by stock;
format date date9.;
run;
*你可以在sas.communities找到类似的问题;
data old;
do id=49,129,185;
do monthi=1 to 12;
lprice=-3-ranuni(0);
output;
end;
end;
run;
data oldmiss;
set old;
if id=49 and monthi=10 then delete;
if id=129 and monthi in (2,3) then delete;
if id=185 and monthi in (5,6,7,8) then delete;
run;
proc print data=oldmiss;
title "Original raw data with month gaps";
run;
data new;
set oldmiss;
by id monthi;
if _N_=1 or first.id then do;
month=1;
end;
else do;
month+1;
end;
if month<monthi then do;
lprice_hold=lprice;
monthi_hold=monthi;
do i=1 to monthi-month;
lprice=0; monthi=month;
output;
month=month+1;
end;
lprice=lprice_hold;
monthi=monthi_hold;
output;
end;
else output;
drop i monthi_hold lprice_hold month;
run;