BookmarkSubscribeRSS Feed
mmovahed
Fluorite | Level 6

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
Fluorite | Level 6
Hi

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

M

hackathon24-white-horiz.png

The 2025 SAS Hackathon Kicks Off on June 11!

Watch the live Hackathon Kickoff to get all the essential information about the SAS Hackathon—including how to join, how to participate, and expert tips for success.

YouTube LinkedIn

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 1670 views
  • 0 likes
  • 4 in conversation