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 ...?
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;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;Look at PROC STDIZE
And another double-post: https://communities.sas.com/t5/Base-SAS-Programming/Missing-value-Imputation-for-Grouped-Data/m-p/40...
Please don't post one question in multiple groups, this just causes confusion and those willing to help may waste time.
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 | 
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;@andreas_lds @Naveen1 please note that I've merged your duplicate posts into a single one.
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
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.
Ready to level-up your skills? Choose your own adventure.
