Encuentre el primer valor str no faltante en el panel y use el valor para reenviar y rellenar por grupo (SAS o PROC SQL)
Tengo un conjunto de datos que contiene un panel de observaciones desequilibradas, donde deseo completar hacia adelante y hacia atrás las observaciones de ticker faltantes y / u "incorrectas" con la última cadena no faltante.
id time ticker_have ticker_want
------------------------------
1 1 ABCDE YYYYY
1 2 . YYYYY
1 3 . YYYYY
1 4 YYYYY YYYYY
1 5 . YYYYY
------------------------------
2 4 . ZZZZZ
2 5 ZZZZZ ZZZZZ
2 6 . ZZZZZ
------------------------------
3 1 . .
------------------------------
4 2 OOOOO OOOOO
4 3 OOOOO OOOOO
4 4 OOOOO OOOOO
ásicamente, si la observación ya tiene un ticker, pero este ticker no es el mismo que el último ticker no vacío, reemplazamos este ticker con el último ticker.
Hasta ahora, he logrado completar las observaciones faltantes utilizando este código
proc sql;
create table have as select * from old_have order by id, time desc;
quit;
data want;
drop temp;
set have;
by id;
/* RETAIN the new variable*/
retain temp; length temp $ 5;
/* Reset TEMP when the BY-Group changes */
if first.id then temp=' ';
/* Assign TEMP when X is non-missing */
if ticker ne ' ' then temp=ticker;
/* When X is missing, assign the retained value of TEMP into X */
else if ticker=' ' then ticker=temp;
run;
Ahora estoy atascado descubriendo los casos en los que no puedo acceder al valor no perdido usandolast.ticker
ofirst.ticker
...
¿Cómo se haría esto usandoDATA
oPROC SQL
o cualquier otro comando SAS?