Sas 与滞后函数相比的替代编码?

Sas 与滞后函数相比的替代编码?,sas,Sas,我希望有一种更有效的方法来进行这种插补。我想要的是在缺少CID的行上复制变量CID的值。对于在日期1、14、28和42报告CID=1818的instace 我编写的程序运行良好,但我想知道是否有其他更简单的方法来执行此操作。请注意,此处不能使用RETAIN DATA test; infile cards dlm='' dsd ; input cid $ @6 days $ @9 CH @13 CL ; cards; 1818 -2 117 46

我希望有一种更有效的方法来进行这种插补。我想要的是在缺少CID的行上复制变量CID的值。对于在日期1、14、28和42报告CID=1818的instace

我编写的程序运行良好,但我想知道是否有其他更简单的方法来执行此操作。请注意,此处不能使用RETAIN

DATA test;
    infile cards dlm=''  dsd ;
    input cid $  @6 days  $ @9 CH  @13  CL ;

    cards;
    1818 -2 117 46
         1  107 45
         14 97  46
         28 104 46
         42 106 44
    5684 -2 100 62
         1  58  78
         14 87  46
         28 102 45
         42 155 41
         ;
    RUN;


    options mprint mlogic symbolgen;
    %macro lag(var,num);
    %do i=2 %to &num.;
    sub&i.=lag&i.(&var);
    if cid=' ' then cid=sub&i.;
    /*drop sub&i.;*/
    %end;
    %mend lag;

    data test_1 ;set test;
    sub=lag(cid);
    if cid=' ' then cid=sub;
    %lag(cid,5);
    run;

为什么不能使用

data want;
  set test;
  retain _cid;
  if not missing(cid) then _cid=cid;
  else cid=_cid;
  drop _cid;
run;

为什么不能使用

data want;
  set test;
  retain _cid;
  if not missing(cid) then _cid=cid;
  else cid=_cid;
  drop _cid;
run;

为什么不能使用

data want;
  set test;
  retain _cid;
  if not missing(cid) then _cid=cid;
  else cid=_cid;
  drop _cid;
run;

为什么不能使用

data want;
  set test;
  retain _cid;
  if not missing(cid) then _cid=cid;
  else cid=_cid;
  drop _cid;
run;

检查这个答案:@Jeff Update不能使用,因为它需要一个BY语句(在这种情况下是不可能的)。@sas_kappel我想你的意思是“不能使用”,所以我添加了t。检查这个答案:@Jeff Update不能使用,因为它需要一个BY语句(在这种情况下是不可能的)。@sas_kappel我想你的意思是“不能使用”,所以我添加了t。检查这个答案:@Jeff Update不能使用,因为它需要BY语句(在这种情况下是不可能的)。@sas_kappel我想你的意思是“不能使用”,所以我添加了t。检查这个答案:@Jeff Update不能使用,因为它需要BY语句(在这种情况下是不可能的)@sas_kappel我猜你的意思是“不能使用”,所以我加上了t。