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

I am trying to write code to handle missing items from survey data. The survey is the AM-PAC outpatient basic mobility (contains 18 questions), and per the survey instructions, to score surveys with missing data, you are supposed to find the average score for the survey's non-missing items, and then input that average score for the missing items.

 

Here is a snapshot of my data:

rauzim_0-1668462744853.png

So you can see in obs 5 (pid SP_002), there are 3 missing items (highlighted in yellow); I've added a variable for the row mean (ampac_mean), and this rows mean is the value highlighted in yellow in the last column. 

 

How do I input that value (2.13) for the missing items in that row? 

I have additional rows with missing data so I will need to be able to input that row's mean value into the missing items. 

 

Thank you,

Michelle

1 ACCEPTED SOLUTION

Accepted Solutions
fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10
data work.TestData;
	input Test09-Test11 Mean;
	datalines;
	1 2 3 2
	. 4 5 4.5
	6 . 8 7
	8 9 . .
	;
run;

data work.TestDataImputed;
	set work.TESTDATA;
	array Cols(*) Test09-Test11;
	
	if not missing(Mean) then do;
		/* Loop over cols */
		do i=1 to dim(Cols);
			if missing(Cols(i)) then Cols(i) = Mean;
		end;
	end;	
run;

or something similar ...

View solution in original post

2 REPLIES 2
fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10
Hello!
As it appears to me that you do not want to calculate the values yourself, why not having an array of values and looping over it ... checking for . ?
Regards
fja
Lapis Lazuli | Level 10 fja
Lapis Lazuli | Level 10
data work.TestData;
	input Test09-Test11 Mean;
	datalines;
	1 2 3 2
	. 4 5 4.5
	6 . 8 7
	8 9 . .
	;
run;

data work.TestDataImputed;
	set work.TESTDATA;
	array Cols(*) Test09-Test11;
	
	if not missing(Mean) then do;
		/* Loop over cols */
		do i=1 to dim(Cols);
			if missing(Cols(i)) then Cols(i) = Mean;
		end;
	end;	
run;

or something similar ...

sas-innovate-white.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9.

 

Early bird rate extended! Save $200 when you sign up by March 31.

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

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