我的问题与 reading next observation's value in current observation 非常相似除了我想阅读下一个非缺失观察结果(SAS 格式)。
例如,这是我的数据集
data have;
input ID Salary;
cards;
10 1000
20 .
30 3000
40 .
50 .
60 6000
;
run;
我正在寻找这样的东西
ID Salary
10 1000
20 3000
30 3000
40 6000
50 6000
60 6000
如您所见,对于 ID 为 40 的情况,工资从下一个非缺失观察中获取值,即 ID 为 60、6000 的值。
最佳答案
链接的问题给出了一些建议,其中大部分都可以适应这一点。
例如,可以稍微修改已接受的答案。
data want;
set have;
if missing(salary) then
do _i = _n_+1 to nobs;
set have(keep=salary) nobs=nobs point=_i;
if not missing(salary) then leave;
end;
run;
您还可以对数据进行反向排序并使用retain 来完成相同的任务。如果你有很多缺失,这可能会更有效。
关于sas - 读取当前观测中的下一个非缺失观测值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29257317/