How to Calculate Standard Deviation in SAS (3 Examples)

Calculating standard deviation in SAS is a simple process that involves using the PROC MEANS or PROC UNIVARIATE procedure. Each procedure requires slightly different syntax, so it is important to know which one is applicable to your dataset. Examples of both procedures are provided, which demonstrate how to calculate standard deviation for a single variable, multiple variables, and a subset of a dataset.


You can use the following methods to calculate the of values in SAS:

Method 1: Calculate Standard Deviation of One Variable

proc means data=my_data std;
    var variable1;
run;

Method 2: Calculate Standard Deviation of All Numeric Variables

proc means data=my_data std;
run;

Method 3: Calculate Standard Deviation by Group

proc means data=my_data std;
    class grouping_variable;
    var values_variable;
run;

The following examples show how to use each method with the following dataset in SAS:

/*create dataset*/
data my_data;
    input team $ points rebounds;
    datalines;
A 23 6
A 31 5
A 33 5
A 18 8
A 20 9
A 25 12
B 18 10
B 20 7
B 17 8
B 14 3
B 14 3
B 15 6
;
run;

/*view dataset*/
proc print data=my_data;

Example 1: Calculate Standard Deviation of One Variable

The following code shows how to calculate the standard deviation of just the points variable.

proc means data=my_data std;
    var points;
run;

The standard deviation of the points variable turns out to be 6.2716.

Example 2: Calculate Standard Deviation of All Numeric Variables

The following code shows how to calculate the standard deviation of all numeric variables in the dataset:

proc means data=my_data std;
run;

From the output we can see that the standard deviation for points is 6.2716 and the standard deviation for rebounds is 2.7247.

Since the standard deviation for points is larger, this tells us that the values are more spread out for the points variable compared to the rebounds variable.

Example 3: Calculate Standard Deviation by Group

The following code shows how to calculate the standard deviation of points, grouped by team:

proc means data=my_data std;
    class team;
    var points;
run;

From the output we can see that the standard deviation of points for team A is 5.9665 and the standard deviation of points for team B is 2.4221.

The following tutorials explain how to perform other common tasks in SAS:

x