BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
chinna0369
Pyrite | Level 9

Hi,

 

I have 10 variables v1 v2 v3 v4 v5 v6 v7 v8 v9 v10. I want to assign mean of others when one of them is missing. I am uisng below code but it looks like it is not working. Can you please help me with this.

 

proc stdize data=have reponly method=mean out=want;
	var v1-v10;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
data_null__
Jade | Level 19

CALL STDIZE

 

data have;
   input id avisitn v1 v2 v3 v4 v5 v6 v7 v8 v9;
   call stdize('none','replace','missing=',mean(of v:),of v:);
   datalines;
1 1320 0 0 . 0 0 0 0 0 1 0
2 1160 0 . 0 1 0 0 0 0 0 0
;
   run;
proc print;
   run;

Capture.PNG

 

View solution in original post

8 REPLIES 8
Kurt_Bremser
Super User

Where is usable example data in a DATA step with DATALINES?

Where is the log?

Where is a clear description why the outcome does not meet your expectations?

 

We really should not need to ask for this from a user with 147 posts here.

ballardw
Super User

@chinna0369 wrote:

Hi,

 

I have 10 variables v1 v2 v3 v4 v5 v6 v7 v8 v9 v10. I want to assign mean of others when one of them is missing. I am uisng below code but it looks like it is not working. Can you please help me with this.

 

proc stdize data=have reponly method=mean out=want;
	var v1-v10;
run;

What exactly is "mean of others" in terms of calculations?

 

The code you show tells SAS to replace the missing values of each variable with mean of that variable.

Example small data set:

data have;
  input obs v1 v2;
datalines;
1   1   .
2   1   2
3   1   3
4   1   4
5   1   5
6   .   6
7   1   7
8   1   8
9   1   9
10  1   10
;

Proc stdize data=have reponly method=mean out=want;
   var v1 v2;
run;

This imputes a value of 1 for variable V1 on obs 6 and for V2 on obs 1 imputes 6.

What values would you want given your " mean of others " rule?

chinna0369
Pyrite | Level 9

Sorry, for not giving proper details. Below is the data and procedure I am using result should be mean for missing variable which is 1/8=0.125 here.

 

data have;
input id 1-2 visitn 3-7 v1 v2 v3 v4 v5 v6 v7 v8 v9;
datalines;
1 1320 0 0 . 0 0 0 0 0 1 0
2 1160 0 . 0 1 0 0 0 0 0 0
;
run;

proc stdize data=have reponly method=mean out=want;
	var v1 v2 v3 v4 v5 v6 v7 v8 v9;
run;
ballardw
Super User

Not a job for Stdize. Your rule is observation based not variable across observations.

 

data want;
   set have;
   array v (*) v1-v9;
   /* calculate the mean of the values present before
      changing any of them
   */
   replacement = mean (of v(*));
   /* replace the missing values with the replacement value*/
   do i=1 to dim(v);
      if missing(v[i]) then v[i]=replacement;
   end;
   drop replacement;
run;

Arrays are often indicated as a choice when doing similar things to multiple variables.

data_null__
Jade | Level 19

CALL STDIZE

 

data have;
   input id avisitn v1 v2 v3 v4 v5 v6 v7 v8 v9;
   call stdize('none','replace','missing=',mean(of v:),of v:);
   datalines;
1 1320 0 0 . 0 0 0 0 0 1 0
2 1160 0 . 0 1 0 0 0 0 0 0
;
   run;
proc print;
   run;

Capture.PNG

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 8 replies
  • 853 views
  • 0 likes
  • 4 in conversation