回填缺失值

问题描述 投票:0回答:1

假设有以下内容:


data DB1;
  input ID Index;
cards;
0001  .    
0001  1 
0003  .
0003  5
0004  .
0004  .
0004  2
;


data DB2;
  input ID Index;
cards;
0001  1    
0001  1 
0003  5
0003  5
0004  2
0004  2
0004  2
;

DB1 在每个 ID 的最后一个可用行处都有一个索引。有没有办法用ID最后一行中的值填充ID最后一行之前的缺失值? DB2 是所需的输出。

提前谢谢您

sas
1个回答
0
投票

您可以使用串行 DOW 循环。 DOW 循环技术的本质是在 DO 循环中包含 SET 语句

示例:

data want;
  if 0 then set have ; * prep PDV ;

  do _n_ = 1 by 1 until (not missing(index)) ;
    set have ;
  end ;
  backfill = index ;
  do _n_ = 1 to _n_ ;
    index = backfill ;
    output ;
  end ;
  drop backfill ;
run ;
© www.soinside.com 2019 - 2024. All rights reserved.