If you want to do last observation carried forward, then UPDATE can make this simple and eliminate the need for new variables or RETAIN statement.
data want ;
update have(obs=0) have ;
by cust_id;
output;
run;
If there are some variables that you did NOT want to apply this LOCF logic to then one way to do that is to add another SET statement to pull back in the observation. You can use either a DROP= or KEEP= dataset option depending whether it is easier to list the variable you want to retain or those that you don't.
data want ;
update have(obs=0) have ;
by cust_id;
set have(drop= variables_to_retain );
output;
run;
But if you really want to replace the missing values with the value from the FIRST observation then that will not work and your posted code will not work either since both are replacing the missing value with the last non-missing value instead of the first value (or the first non-missing value).
You might be able to get the replace with first option to work if you used something like this.
data want ;
set have ;
retain P 1 ;
if missing(X) then set have(keep=X) point=p ;
if missing(Y) then set have(keep=Y) point=p ;
run;
But that will not work if you want to do it BY some ID variable.
You might do that by adding some BY processing.
data want ;
set have ;
by id;
if first.id then p=_n_;
retain P ;
if missing(X) then set have(keep=X) point=p ;
if missing(Y) then set have(keep=Y) point=p ;
run;
... View more