BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi, I'm trying to creat new datasets that contains missing vlaues using exist data.

If I have a data that contains 7 continuous variables like below.

A B C D E F G
1 3 4 3 2 3 4
2 4 3 4 5 6 2
2 5 3 4 5 3 1
1 2 3 3 2 1 3
2 5 4 3 4 1 3

I want to make missing randomly, but same number of missing within each person like below.

data-1 (1 missing per person)

A B C D E F G
1 . 4 3 2 3 4
2 4 3 . 5 6 2
2 5 . 4 5 3 1
. 2 3 3 2 1 3
2 5 4 3 4 . 3

data-2 (2 missing per person)

A B C D E F G
1 . 4 3 . 3 4
2 4 . . 5 6 2
2 5 . 4 5 . 1
. 2 3 3 . 1 3
2 5 . 3 4 . 3

...up to 6 missings per person.

Also, is there any way to replace the missing value with mean of rest of values?

Thanks.
2 REPLIES 2
ArtC
Rhodochrosite | Level 12
This DATA step will create the randomly missing values. A simple extension could be used to create n randomly missing values.
[pre]data missran;
input A B C D E F G;
array allvar {7} a--g;
* randomly set one var to missing;
loc = ceil(ranuni(0)*dim(allvar));
allvar{loc} = .;
* replace missing with mean of other vars;
allvar{loc} = mean(of a--g);
datalines;
1 3 4 3 2 3 4
2 4 3 4 5 6 2
2 5 3 4 5 3 1
1 2 3 3 2 1 3
2 5 4 3 4 1 3
run;
proc print data=missran;
run;
[/pre]
deleted_user
Not applicable
Thanks a lot!!

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

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.

SAS Training: Just a Click Away

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

Browse our catalog!

Discussion stats
  • 2 replies
  • 1186 views
  • 0 likes
  • 2 in conversation