24.3 C
London
Thursday, June 12, 2025
HomeSASDescriptive Statistics in SASHow to Calculate Z-Scores in SAS

How to Calculate Z-Scores in SAS

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

In statistics, a z-score tells us how many standard deviations away a value is from the mean.

We use the following formula to calculate a z-score:

z = (X – μ) / σ

where:

  • X is a single raw data value
  • μ is the mean of the dataset
  • σ is the standard deviation of the dataset

The following example shows how to calculate z-scores for raw data values in SAS.

Example: Calculate Z-Scores in SAS

Suppose we create the following dataset in SAS:

/*create dataset*/
data original_data;
    input values;
    datalines;
7
12
14
12
16
18
6
7
14
17
19
22
24
13
17
12
;
run;

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

Now suppose we would like to calculate the z-score for each value in the dataset.

We can use proc sql to do so:

/*create new variable that shows z-scores for each raw data value*/
proc sql;
    select values, (values - mean(values)) / std(values) as z_scores
    from original_data;
quit;

z-scores in SAS

The values column shows the original data values and the z_scores column shows the z-score for each value.

How to Interpret Z-Scores in SAS

A z-score tells us how many standard deviations away a value is from the mean.

A z-score can be positive, negative, or equal to zero.

A positive z-score indicates that a particular value is greater than the mean, a negative z-score indicates that a particular value is less than the mean, and a z-score of zero indicates that a particular value is equal to the mean.

If we calculated the mean and standard deviation of our dataset, we would find that the mean is 14.375 and the standard deviation is 5.162.

So, the first value in our dataset was 7, which had a z-score of (7-14.375) / 5.162 = -1.428. This means that the value “7” is 1.428 standard deviations below the mean. 

The next value in our data, 12, had a z-score of (12-14.375) / 5.162 = -0.46.  This means that the value “12” is 0.46 standard deviations below the mean. 

The further away a value is from the mean, the higher the absolute value of the z-score will be for that value.

For example, the value 7 is further away from the mean (14.375) compared to 12, which explains why 7 had a z-score with a larger absolute value.

Additional Resources

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

How to Identify Outliers in SAS
How to Calculate Percentiles in SAS
How to Calculate Mean, Median, & Mode in SAS

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories