Skip to content

Instantly share code, notes, and snippets.

@statgeek
Last active October 25, 2017 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statgeek/cbd6bd253b4ab4828dd71d0ce3d17199 to your computer and use it in GitHub Desktop.
Save statgeek/cbd6bd253b4ab4828dd71d0ce3d17199 to your computer and use it in GitHub Desktop.
SAS - Replace missing values with Mean
*Create sample with missing data;
data missing;
set sashelp.class;
if mod(_n_, 2) eq 1 then
call missing(of _numeric_);
run;
*Display for example purposes;
title 'Original data';
proc print ;
run;
*Show mean values to check results;
title 'Mean results to check output' proc means data=missing mean;
run;
*Replace missing with mean, for ALL NUMERIC variables. If you want specific variables
add them via a VAR statement;
proc stdize out=class_mean reponly method=mean;
run;
*Diplay results for example;
title 'Final - Missing replaced with Mean';
proc print data=class_mean;
run;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment