Hi. I have this data set (example)
City days X 0X X 5Y 1Y 3Y 7
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 meanX 2.5Y 3.5
City mean
X 2.5
Y 3.5
Y
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;
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;
Nearly 200 sessions are now available on demand with the SAS Innovate Digital Pass.
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.