## Mean imputation

Solved
Occasional Contributor
Posts: 12

# Mean imputation

Hi,

Need help, I want to impue the data for grouped data based on variabke Region,

Data set:

 Country Region Age Nigeria Africa 15 Ethiopia Africa Egypt Africa 42 Democratic Republic of Congo Africa South Africa Africa 13 Russia Europe 45 Germany Europe 54 France Europe 17 United Kingdom Europe 60 Italy Europe

Africa Region mean : 23 and Europe Region mean :44

Expected Output:

 Country Region Age Nigeria Africa 15 Ethiopia Africa 23 Egypt Africa 42 Democratic Republic of Congo Africa 23 South Africa Africa 13 Russia Europe 45 Germany Europe 54 France Europe 17 United Kingdom Europe 60 Italy Europe 44

I have so many Levels in (Regions), by writing if condition will take much time. So is there any other method ...?

Accepted Solutions
Solution
‎10-10-2017 02:54 AM
Super User
Posts: 10,850

## Re: Missing value Imputation for Grouped Data

``````data have;
infile cards expandtabs truncover;
input Country	& \$40. Region & \$20.	Age;
cards;
Nigeria 	Africa	     15
Ethiopia	Africa
Egypt	Africa	  42
Democratic Republic of Congo	Africa
South Africa	Africa	 13
Russia	 Europe	 45
Germany 	Europe	     54
France	 Europe	 17
United Kingdom	 Europe	 60
Italy	Europe
;
run;
proc stdize data=have out=want reponly missing=mean;
by region;
var age;
run;``````

All Replies
Super Contributor
Posts: 359

## Re: Mean imputation

Hello,

With SQL :

``````proc sql;
CREATE TABLE want AS
SELECT country, region,
CASE WHEN age NOT IS MISSING THEN age ELSE round(mean(age)) END AS age
FROM HAVE
GROUP BY region;
quit;``````
Super User
Posts: 24,010

## Re: Mean imputation

Look at PROC STDIZE

Valued Guide
Posts: 629

## Re: Mean imputation

Please don't post one question in multiple groups, this just causes confusion and those willing to help may waste time.

Occasional Contributor
Posts: 12

## Missing value Imputation for Grouped Data

Hi,

Need help to impute the missing values by mean for the group data,

Data :

 Country Region Age Nigeria Africa 15 Ethiopia Africa Egypt Africa 42 Democratic Republic of Congo Africa South Africa Africa 13 Russia Europe 45 Germany Europe 54 France Europe 17 United Kingdom Europe 60 Italy Europe

Mean of Africa=23 and Mean of Europe =44

Expected Output:

 Country Region Age Nigeria Africa 15 Ethiopia Africa 23 Egypt Africa 42 Democratic Republic of Congo Africa 23 South Africa Africa 13 Russia Europe 45 Germany Europe 54 France Europe 17 United Kingdom Europe 60 Italy Europe 44

Solution
‎10-10-2017 02:54 AM
Super User
Posts: 10,850

## Re: Missing value Imputation for Grouped Data

``````data have;
infile cards expandtabs truncover;
input Country	& \$40. Region & \$20.	Age;
cards;
Nigeria 	Africa	     15
Ethiopia	Africa
Egypt	Africa	  42
Democratic Republic of Congo	Africa
South Africa	Africa	 13
Russia	 Europe	 45
Germany 	Europe	     54
France	 Europe	 17
United Kingdom	 Europe	 60
Italy	Europe
;
run;
proc stdize data=have out=want reponly missing=mean;
by region;
var age;
run;``````
Super User
Posts: 24,010