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

Hi,

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

Data set:

CountryRegionAge
NigeriaAfrica15
EthiopiaAfrica 
EgyptAfrica42
Democratic Republic of CongoAfrica 
South AfricaAfrica13
RussiaEurope45
GermanyEurope54
FranceEurope17
United KingdomEurope60
ItalyEurope 

 

Africa Region mean : 23 and Europe Region mean :44

Expected Output:

CountryRegionAge
NigeriaAfrica15
EthiopiaAfrica23
EgyptAfrica42
Democratic Republic of CongoAfrica23
South AfricaAfrica13
RussiaEurope45
GermanyEurope54
FranceEurope17
United KingdomEurope60
ItalyEurope44

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

1 ACCEPTED SOLUTION

Accepted Solutions
Ksharp
Super User
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;

View solution in original post

6 REPLIES 6
gamotte
Rhodochrosite | Level 12

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;
Reeza
Super User

Look at PROC STDIZE 

andreas_lds
Jade | Level 19

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.

Naveen1
Calcite | Level 5

Hi,

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

Data :

CountryRegionAge
NigeriaAfrica15
EthiopiaAfrica 
EgyptAfrica42
Democratic Republic of CongoAfrica 
South AfricaAfrica13
RussiaEurope45
GermanyEurope54
FranceEurope17
United KingdomEurope60
ItalyEurope

 

 

Mean of Africa=23 and Mean of Europe =44

Expected Output:

CountryRegionAge
NigeriaAfrica15
EthiopiaAfrica23
EgyptAfrica42
Democratic Republic of CongoAfrica23
South AfricaAfrica13
RussiaEurope45
GermanyEurope54
FranceEurope17
United KingdomEurope60
ItalyEurope44

 

 

Ksharp
Super User
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;
Reeza
Super User

@andreas_lds @Naveen1 please note that I've merged your duplicate posts into a single one. 

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

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
  • 6 replies
  • 2341 views
  • 7 likes
  • 5 in conversation