BookmarkSubscribeRSS Feed
mmea
Quartz | Level 8

Hi. I have this data set (example)

 

City           days        

X                0

X                

X                5

Y                1

Y                3

Y                7

How can i make a new column with the mean days for each city even  though i have missing values ?

I want this out out

City  mean

X      2.5

Y       3.5

 

Y

 

2 REPLIES 2
PaigeMiller
Diamond | Level 26

PROC MEANS or PROC SUMMARY will do the calculations and properly ignore the missings, and allow you to create the new data set.

 

proc summary data=have nway;
    class city;
    var days;
    output out=want mean=;
run;
--
Paige Miller
Angel_Larrion
SAS Employee

The mean function ignores missing values, so you can use it in a proc sql to obtain what you want.

proc sql;
create table want as
select city , mean(days) as mean from have
group by city;
quit;

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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
  • 528 views
  • 0 likes
  • 3 in conversation