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!!

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
  • 2 replies
  • 774 views
  • 0 likes
  • 2 in conversation