/***************************************************************************************************************** SAS file name: Replace_Missing_Mean.sas File location: _________________________________________________________________________________________________________________ Purpose: To demonstrate how to replace missing values with group mean or other statistics in SAS using PROC STDIZE Author: Peter Clemmensen Creation Date: 22/03/2017 This program supports the blog post "Replace Missng Values With Mean" on SASnrd.com _________________________________________________________________________________________________________________ CHANGES: Date: Date of first modification of the code Modifyer name: Name of the programmer who modified the code Description: Shortly describe the changes made to the program *****************************************************************************************************************/ /* Example Data */ data Missing_Values; input ID$ var1 var2 var3 @@; datalines; 1 . 3 4 1 4 . 2 1 . . . 1 2 8 . 2 2 0 . 2 5 . 1 2 . 4 . 3 . . 3 3 5 . 7 3 3 1 7 3 . . 2 3 3 . 7 3 . 1 9 ; /* Sort by ID */ proc sort data=Missing_Values; by ID; run; /* Replace missing values with group mean */ proc stdize data=Missing_Values out=Missing_Values_Mean reponly missing=mean; by ID; run;