BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
PhanS
Obsidian | Level 7

I am handling a cross-sectional data set.

I identified that a number of my variable of interests were missing values, including continued, bi-variate and ordinal data. 

I am wondering if I can replace the missing values by its mean or median.     

And I want to know if there is a cap for allowing the replacing its value, e.g., missing values must less than 10% or so.  

 

Anyone can help much appreciated.

 

Phan S.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

Here's an inefficient macro that will cap the outliers. 

https://gist.github.com/statgeek/31316a678433a1db8136

 

PROC STDIZE is a better option for replacing with median/mean. You can also look into PROC MI, multiple imputation to impute missing data. 

 

View solution in original post

5 REPLIES 5
stat_sas
Ammonite | Level 13

Hi,

 

Missing values can be replaced with various statistics using proc stdize. Below is an example replacing missing values with median.

Defining a cap would be based on your analysis. You can flag variables containing a certain percentage of missing values for imputation.

 

 

 

proc stdize data=have reponly method=median out=imputed;
var a b c; /* Assuming a, b and c are 3 numeric variables */
run;

PhanS
Obsidian | Level 7

Hello,

 

I am sorry, I mean I give the solution (credit) to you, bu accidentally check to Reeza. 

 

Thank you for you code.

 

Phan S. 

 

Reeza
Super User

@PhanS You can change that to @stat_sas, just select theirs instead.

stat_sas
Ammonite | Level 13

Hi,

 

I am glad you have the solution. I am also  learning from @Reeza's posts Smiley Happy

 

Reeza
Super User

Here's an inefficient macro that will cap the outliers. 

https://gist.github.com/statgeek/31316a678433a1db8136

 

PROC STDIZE is a better option for replacing with median/mean. You can also look into PROC MI, multiple imputation to impute missing data. 

 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 1125 views
  • 0 likes
  • 3 in conversation