我是搞气象分析的,在处理数据过程中遇到了一些问题,希望大家能够给予帮助。在sas编程中有没有关于缺失数据的插补程序。比如说:有一天的数据,数据步长为半个小时,那么一天就有48个数据,但是由于其他原因(仪器failure or bad weather condition)我们必须剔除这些数据,所以数据变得不连续,但是需要一天完整的数据。为了插补这些数据,必须用adjacent days data 来插补,就是前后几天同一时刻的数据的平均作为那天的数据。请问怎么样能够用nonlienar 回归来插补这些数据。
用非线性回归方法不知道怎么做,但用SQL的UPDATE语句也可以实现线性插值。举个例子:
/** 1. 生成数据 **/
data temp1(drop=i j);
date=mdy(1,1,2004);
do i=1 to 5;
date=date+1;
do j=1 to 5;
time=j*1800;
if i=3 and j=3 then obs1=.;
else obs1=rannor(1)*4+5;
output;
end;
end;
format date yymmdd10. time time5. obs1 6.2;
run;
/** 2. 提取出缺失数据 **/
data temp2;
set temp1;
where obs1=.;
retain i 0;
i=i+1;
run;
/**3.如果数据缺失,用前后2天的数据补齐 **/
%macro update(i);
proc sql noprint;
select date+0 into:date from temp2 where i=&i;
select time+0 into:time from temp2 where i=&i;
reset undo_policy=optional;
update temp1
set obs1 = ( select avg(obs1) from temp1 where time=&time and (date>=&date-2 and date<=&date+2))
where time=&time and date=&date;
reset undo_policy=required;
quit;
%mend update;