PROC UNIVARIATE with the BY Statement in SAS
PROC UNIVARIATE with the BY Statement in SAS, you can utilize PROC UNIVARIATE
along with the BY
statement to compute descriptive statistics for numeric variables, grouped by a specified variable.
PROC UNIVARIATE with the BY Statement in SAS
This enables a detailed examination of the data segmented by different categories.
Basic Syntax
The general syntax for this procedure is as follows:
proc univariate data=my_data normal;
by group_variable;
run;
Example: Calculating Descriptive Statistics by Group
Let’s demonstrate how to apply this in practice using a dataset containing information about various basketball players.
/* Create dataset */
data my_data;
input team $ points rebounds;
datalines;
A 12 8
A 12 8
A 12 8
A 23 9
A 20 12
A 14 7
A 14 7
B 20 2
B 20 5
B 29 4
B 14 7
B 20 2
B 20 2
B 20 5
;
run;
/* View dataset */
proc print data=my_data;
run;
In order to calculate the descriptive statistics for the points
and rebounds
variables, segmented by the team
variable, you can use the following code:
proc univariate data=my_data;
by team;
run;
Results Interpretation
This procedure will generate separate descriptive statistics for the points
and rebounds
variables for each team. For instance, you would see results such as:
- Descriptive statistics for
points
for Team A - Descriptive statistics for
rebounds
for Team A - Descriptive statistics for
points
for Team B - Descriptive statistics for
rebounds
for Team B
If you are specifically interested in calculating descriptive statistics for just one variable, you can focus on that variable by using the VAR
statement.
Here’s how to calculate descriptive statistics exclusively for the points
variable, grouped by the team
variable:
proc univariate data=my_data;
var points;
by team;
run;
Flexibility with Multiple Variables
You can also specify multiple variables in both the VAR
and BY
statements to compute descriptive statistics for various variables grouped by the same or different categorical variables.
This flexibility allows for a comprehensive analysis based on the specific needs of your study.
Conclusion
Using PROC UNIVARIATE
with the BY
statement provides a powerful way to explore and summarize descriptive statistics in SAS, allowing for insights that are segmented by categorical groups in your dataset.