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: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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