Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Home
- /
- Analytics
- /
- Stat Procs
- /
- Re: Easy way to calculate Cohen's d

Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

☑ This topic is **solved**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 03-09-2022 11:32 AM
(9608 views)

I am trying to calculate Cohen's d in SAS. This is such a common statistic, I do not understand why it is not available in SAS. I can calculate it by hand or using an online calculator like https://www.socscistatistics.com/effectsize/default3.aspx

But I will need to do it 100 times and am certain to make an error copying and pasting data.

I found a macro for calculating effect size but I cannot get it to run.

There must be simple code I can use to do the calculation in the above website within SAS. Any help is appreciated. Thank you!

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I'm not familiar with Cohen's D, but PROC TTEST provides estimates for the difference between group means and for the pooled standard deviation. You can write those statistics to a data set and then use a DATA step to compute the ratio, as follows:

```
ods trace on;
title;
proc ttest data=sashelp.class plots=none;
class Sex;
var Height;
ods select ConfLimits;
ods output ConfLimits=CL;
run;
data CohenD;
set Cl(where=(method="Pooled") rename=(Mean=MeanDiff));
CohenD = MeanDiff / StdDev;
run;
proc print data=CohenD noobs;
var Variable Class Method MeanDiff StdDev CohenD;
run;
```

14 REPLIES 14

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I do not understand why it is not available in SAS

if you click on the magnifying glass search icon right here in the SAS communities, and type in Cohen's D, you find that you can compute this in SAS, and there is at least one thread marked correct that asks about Cohen's D.

As far a this goes:

But I will need to do it 100 times and am certain to make an error copying and pasting data.

Without much more information and detail, there's really no way to help you. We would need to see (a portion of) the data to see how it is structured, and where the "100 times" comes into play. Please provide a portion of your SAS data set via SAS data step code which you type in yourself or via these instructions, and not in any other format.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

The thread uses Proc Mixed and I simply do not understand it. Why is this not part of t-test or GLM? PROC GLM has an effectsize option, but it doesn't report Cohen's d.

I have a dataset with two independent groups. I want an easy way to do this calculation.

Cohen's *d* = (*M*2 - *M*1) ⁄ *SD*pooled

*SD*pooled = √((*SD*12 + *SD*22) ⁄ 2)

Can this be done as part of a t-test, means, or GLM PROC?

Here's my means statement which gets me all of the calculations I need to do the procedure by hand. I am fine having to run it separately for each dependent variable:

PROC MEANS DATA=surveydata(where=(Scenario="S1" AND SpeakerGender="F")) ;

CLASS SResponse;

Var Comp OriginalSocial Abrasive GetRequest;

RUN;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I see that you asked for my data in a data step. I am really not familiar with the syntax since I upload Excel spreadsheets, but here's my best guess at a simplified version of my data

data surveydata;

input ResponseID SResponse Comp OriginalSocial Abrasive GetRequest SpeakerGender;

datalines;

01 PFF 3.2 5.6 5.0 4 F

02 ISTATE 4.8 2.1 1.0 6 F

03 PFF 3.8 5.9 5.1 4 M

Is that close enough?

Is there a way that SAS can spit out this simple calculation: Cohen's *d* = (*M*2 - *M*1) ⁄ *SD*pooled

Here's a macro for doing it, but I am having trouble figuring out how to run the macro.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

I'm not familiar with Cohen's D, but PROC TTEST provides estimates for the difference between group means and for the pooled standard deviation. You can write those statistics to a data set and then use a DATA step to compute the ratio, as follows:

```
ods trace on;
title;
proc ttest data=sashelp.class plots=none;
class Sex;
var Height;
ods select ConfLimits;
ods output ConfLimits=CL;
run;
data CohenD;
set Cl(where=(method="Pooled") rename=(Mean=MeanDiff));
CohenD = MeanDiff / StdDev;
run;
proc print data=CohenD noobs;
var Variable Class Method MeanDiff StdDev CohenD;
run;
```

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you so much!!! This is exactly what I needed.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hi, how can I calculate Cohen's d for paired t-test?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Make a new variable

diff=after-before;

and use this variable to book in Rick's code .

diff=after-before;

and use this variable to book in Rick's code .

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Can I check, is this code correct?

ods trace on;

title;

proc ttest data=wide1 plots=none;

PAIRED pwb4months*pwbbaseline;

ods select ConfLimits;

ods output ConfLimits=CL;

run;

data CohenD;

set Cl (rename=(Mean=MeanDiff));

CohenD = MeanDiff / StdDev;

run;

proc print data=CohenD noobs;

var MeanDiff StdDev CohenD;

run;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

OK. It looks right.

Also Could try this one :

var Height;

---->

var diff;

Also Could try this one :

var Height;

---->

var diff;

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

thank you. 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

thanks for the solution!

is there any way to request that SAS consider adding this as an option in proc glm or mixed?

is there any way to request that SAS consider adding this as an option in proc glm or mixed?

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Hello, is there a way to compute the 95% CI in the data step for what you have presented? Thank you.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

You could use BOOTSTRAP method to get CI.

@Rick_SAS wrote a couple of blogs about this:

Bootstrap estimates in SAS/IML - The DO Loop

Compute a bootstrap confidence interval in SAS - The DO Loop

Bootstrap confidence intervals for the predicted mean in a regression model - The DO Loop (sas.com)

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Thank you.

I was hoping to include the CI calculation in this presented data step using output data from the proc ttest:

data CohenD;

set Cl (rename=(Mean=MeanDiff));

CohenD = MeanDiff / StdDev;

run;

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. **Registration is now open through August 30th**. Visit the SAS Hackathon homepage.

What is ANOVA?

ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.

Find more tutorials on the SAS Users YouTube channel.