/***************************************************************************************************************** SAS file name: Replace_Missing_Zero.sas File location: _________________________________________________________________________________________________________________ Purpose: To Demonstrate how to replace missing values woth zeros for specific and all numeric variables in a SAS data set using the Data Step and PROC STDIZE Author: Peter Clemmensen Creation Date: 15/11/2016 This program supports the blog post "Replace Missing Values with zero in SAS" on SASnrd.com *****************************************************************************************************************/ /* Example Data */ data Missing_Values; input ID$ var1 var2 var3; datalines; 1 . 3 4 2 2 0 . 3 . . 3 4 . 8 . 5 5 . . ; /* Replace Missing Values with Zero With the Data Step */ data DataStepMethod; set Missing_Values; array NumVar _numeric_; do over NumVar; if NumVar=. then NumVar=0; end; run; /* Replace Missing Values of all numeric variables with Zero With PROC STDIZE */ proc stdize data=Missing_Values out=StdizeMethod_All reponly missing=0; run; /* Replace Missing Values of only the specified variables */ proc stdize data=Missing_Values out=StdizeMethod_Var reponly missing=0; var var1; run;