SAS Macro : Imputing Missing Data

Live Online Training : SAS Programming with 50+ Case Studies

- Explain Programming Concepts in Simple English
- Live Projects
- Scenario Based Questions
- Job Placement Assistance
- Get 10% off till Oct 26, 2017
- Batch starts from October 28, 2017

When building a predictive model, it is important to impute missing data. There are several ways to treat missing data.

The following is a list of options to impute missing values :
  1. Fill missing values with mean value of the continuous variable (for real numeric values) in which NO outlier exists.
  2. Fill missing values with median value of the continuous variable (for real numeric values) in which outlier exists.
  3. Fill missing values with median value of the ordinal categorical variables 
  4. Fill missing values with mode value of the nominal categorical variables
SAS Macro

The following code fills in missing data with mean/median/mode for each of the variables assigned in the macro and saves it into a new data set.

************* Imputing Missing Data **************************/;
*Input : Specify your input dataset name (raw data).
*Stats : Specify mean, median or mode for replacing missing data.
*Vars : Specify your variables in which missing values exist.
- Multiple variables should be seperated by a space.
- The list of variables can be referred as var1-var25.
- For all numeric variables, use _numeric_ keyword.
*Output : Specify dataset where you want ouput file to be saved.

%macro replace (input= prac.file1,stats=median,vars=Q1-Q5,output=replaced);

* Generate analysis results ;
proc univariate data=&input noprint;
var &vars;
output out=dummy &stats= &vars;

* Convert to vertical ;
proc transpose data=dummy out=dummy;

* Replace missing with analysis results ;
data &output;
set &input;
array vars &vars ;
do i =1 to dim(vars);
set dummy(keep=col1) point= i ;
drop col1 ;


Options mprint nosymbolgen;
%replace (input= readin1,stats= mode,vars= dbp scl,output=replaced);

SAS Tutorials : 100 Free SAS Tutorials

About Author:

Deepanshu founded ListenData with a simple objective - Make analytics easy to understand and follow. He has close to 7 years of experience in data science and predictive modeling. During his tenure, he has worked with global clients in various domains like retail and commercial banking, Telecom, HR and Automotive.

While I love having friends who agree, I only learn from those who don't.

Let's Get Connected: Email | LinkedIn

Get Free Email Updates :
*Please confirm your email address by clicking on the link sent to your Email*

Related Posts:

0 Response to "SAS Macro : Imputing Missing Data"

Post a Comment

Next → ← Prev