BookmarkSubscribeRSS Feed
mmovahed
Calcite | Level 5

I like to replace some values of a continuous variable to missing by random. I wonder what is the code in SAS for this.

 

Also Like to know if I can do multiple imputation for variable with whole missing values based on other variables in the data set. If so I wonder what is SAS codes for this as well.

 

Thanks

5 REPLIES 5
PaigeMiller
Diamond | Level 26

@mmovahed wrote:

I like to replace some values of a continuous variable to missing by random. I wonder what is the code in SAS for this.


Seems like an odd thing to do.

 

data want;
    set have;
    random=rand('uniform');
    if random<0.2 then x=.;
run;

 

 

Also Like to know if I can do multiple imputation for variable with whole missing values based on other variables in the data set. If so I wonder what is SAS codes for this as well.

 

Look at the examples in the documentation for PROC MI.

--
Paige Miller
hashman
Ammonite | Level 13

@mmovahed:

The answer depends on whether you want to replace a variable with a missing value:

  1. in an exact number of observations
  2. approximately in some percentage of observations

A program for #1 will be quite different (and more complex - there're different algorithms for doing it) than for #2 at which @PaigeMiller has hinted.

 

And also it depends on whether every time you run the code you want to:

  1. get exactly the same results
  2. get different results
  3. pick the observations on run #n all different from run #m
  4. the missing values to be distributed uniformly or in some other manner

and possibly a number of other factors.

 

Kind regards

Paul D.

 

 

ballardw
Super User

@mmovahed wrote:

Also Like to know if I can do multiple imputation for variable with whole missing values based on other variables in the data set. If so I wonder what is SAS codes for this as well.

 

 


You may need to describe exactly what you mean by "whole missing values ". That sort of sounds like you have no actual values for a variable. Without at least a few values it is going to be real hard to determine any sort of rule that uses other variables to impute.

 

If you have a categorical variable that should have 4 levels but one of the levels doesn't appear, for example, then what rule would be used to determine the missing should be the category with no representation?

mmovahed
Calcite | Level 5
Hi

Thanks for your explanation. You are right. I think we need at least few available values for the variable with missing.

M

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 802 views
  • 0 likes
  • 4 in conversation