/***************************************************************************************************************** SAS file name: Replace_Missing_With_Previous.sas File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to replace missing values with the previous/most recent non missing value Author: Peter Clemmensen Creation Date: 01/12/2017 This program supports the post "Replace Missing Values with Previous" on SASnrd.com *****************************************************************************************************************/ /* Example Data */ data MyData; input ID$ Value; datalines; 1 2 1 . 1 . 1 4 2 . 2 9 2 . 2 . 3 3 3 . 3 0 ; /* Make sure that data is sorted correctly */ proc sort data=MyData; by ID; run; /* Replace missing values with previous by group */ data Want; update MyData(obs=0) MyData; by ID; output; run;