## Determining mean and average from dataset

Occasional Contributor
Posts: 7

# Determining mean and average from dataset

Hi guys. How can I determine the mean and average for fields of the Total Cholesterol and Glucose of an individual based on age and gender of an individual from the diabetes dataset? Should I sort it first? Any help and advice will be appreciated. Thanks

Diabetes File:

Trusted Advisor
Posts: 1,137

## Re: Determining mean and average from dataset

[ Edited ]
Posted in reply to pailek1996

wouldn't you want to categorize the age first, since it is a numeric variable

convert it into a character variable. You could get the means from proc means as below. This is an untested code so please change the variable names as per your dataset. The autoname will create the mean variable names by concatenating the  variable name with statistics name example chol_mean glucose_mean

``````proc means data=have nway;
class age gender;
var chol glucose;
output out=means mean=/autoname;
run;``````

Thanks,
Jag
Trusted Advisor
Posts: 1,931

## Re: Determining mean and average from dataset

[ Edited ]
Posted in reply to pailek1996

You could apply a format to the AGE variable to group it, as explained by @Jim_G in this thread:

https://communities.sas.com/t5/SAS-Enterprise-Guide/Creating-Age-Groups-from-Age-Variable/m-p/370295...

Then you can use PROC MEANS or PROC SUMMARY on the data. If you use PROC SUMMARY with a CLASS statement, no sorting is necessary.

By the way, the "mean" is the same thing as the "average".

Super User
Posts: 19,835

## Re: Determining mean and average from dataset

Posted in reply to pailek1996

If you're using EG and the tasks you can use the Summary Task.

Add age and gender into the GROUP variables and Cholesterol into the analysis variables.

If you're looking for code here's some examples:

https://github.com/statgeek/SAS-Tutorials/blob/master/add_average_value_to_dataset

Discussion stats
• 3 replies
• 182 views
• 1 like
• 4 in conversation