## Calculating the sum or mean of a numeric (continuous) variable by a group (categorical) variable in SAS

October 28, 2014 3 Comments

#### Introduction

A common task in **data analysis** and **statistics** is to calculate the **sum** or **mean** of a continuous variable. If that variable can be categorized into 2 or more classes, you may want to **get the sum or mean for each class**.

This sounds like a simple task, yet I took a surprisingly long time to learn how to do this in SAS and get exactly what I want – a new data with with each category as the identifier and the calculated sum/mean as the value of a second variable. Here is an example to show you how to do it using PROC MEANS.

**Read more to see an example data set and get the SAS code to calculate the sum or mean of a continuous variable by a categorical variable!**

## Recent Comments