Solved: Easy Way To Calculate Cohen's D - SAS Support Communities

  • Community
    • Home
    • Welcome
      • Getting Started
      • Community Memo
      • All Things Community
      • SAS Customer Recognition Awards (2024)
      • SAS Customer Recognition Awards (2023)
    • SAS Community Library
    • SAS Product Suggestions
    • Upcoming Events
    • SAS Customer Recognition Awards
    • All Recent Topics
  • Learn
    • New SAS User
    • SAS Software for Learning Community
    • Ask the Expert
    • SAS Certification
    • SAS Tips from the Community
    • SAS Training
      • Programming 1 and 2
      • Advanced Programming
      • Course Case Studies and Challenges
      • Trustworthy AI
    • SAS Global Forum Proceedings 2021
    • Tech Report Archive
    • SAS Insights Archive
  • Programming
    • SAS Programming
    • SAS Procedures
    • SAS Enterprise Guide
    • SAS Studio
    • Graphics Programming
    • ODS and Base Reporting
    • SAS Code Examples
    • SAS Web Report Studio
    • Developers
  • Analytics
    • Statistical Procedures
    • SAS Data Science
    • Mathematical Optimization, Discrete-Event Simulation, and OR
    • SAS/IML Software and Matrix Computations
    • SAS Forecasting and Econometrics
    • Streaming Analytics
    • Research and Science from SAS
  • SAS Viya
    • SAS Viya
    • SAS Viya on Microsoft Azure
    • SAS Viya Release Updates
    • Moving to SAS Viya
    • SAS Visual Analytics
    • SAS Visual Analytics Gallery
    • Your Journey to Success
    • SAS Viya Workbench
      • SAS Viya Workbench: Getting Started
      • SAS Viya Workbench Discussion
      • SAS Viya Workbench: Release Updates
  • Administration
    • Administration and Deployment
    • Architecture
    • SAS Hot Fix Announcements
    • SUGA
  • Solutions
    • Microsoft Integration with SAS
    • Decisioning
    • SAS Decision Builder
    • Data Management
    • SAS Data Maker
      • SAS Data Maker: Getting Started
      • SAS Data Maker Discussion
    • Customer Intelligence
      • SAS Customer Intelligence
      • SAS Customer Intelligence 360 Release Notes
      • SAS 360 Match
    • Risk and Fraud
      • SAS Risk Management
      • Fraud, AML and Security Intelligence
      • SAS Fraud and Compliance Release Updates
      • SAS Risk Release Updates
      • Risk & Finance Analytics
      • Insurance Fraud
      • MRM AI Governance Working Group
      • SAS Quant Community
    • SAS Health
      • SAS Health and Life Sciences
      • SAS Life Science Analytics Framework
  • Hubs
    • Regional Hubs
      • SAS User Groups
      • SAS Community Nordic
      • AML Nordic User Group
      • SAS Japan
      • SAS Korea
      • CoDe SAS German
      • SAS Plattform Netzwerk
      • SAS Brazil Community
      • SAS Spanish Community
      • SAS Users Group in Israel
      • 欢迎来到SAS中文社区!
      • Ottawa Area SAS Users' Society
      • Toronto Area SAS Users Group
      • SAS Türkiye Community
    • Special Interest Hubs
      • SAS Hacker's Hub
      • SAS Innovate 2026
      • SAS Analytics Explorers
      • The Curiosity Cup
      • SAS Inner Circle Panel
      • SAS Hackathon Team Profiles (Past)
      • SAS Explore
      • Reporting and Optimization
      • Intern Alumni Network Community
Sign In All communityThis categoryThis boardKnowledge baseUsersProducts cancel Turn on suggestions Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type. Showing results for  Search instead for  Did you mean: 
  • Home
  • Analytics
  • Stat Procs
  • Easy way to calculate Cohen's d
Options BookmarkSubscribeRSS Feed
  • All forum topics
  • Previous
  • Next
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question. jowolfe79 Calcite | Level 5 jowolfe79 Calcite | Level 5 Go to Solution

Easy way to calculate Cohen's d

Posted 03-09-2022 11:32 AM (18988 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!

0 Likes Reply 1 ACCEPTED SOLUTION Accepted Solutions Rick_SAS SAS Super FREQ Rick_SAS SAS Super FREQ

Re: Easy way to calculate Cohen's d

Posted 03-09-2022 12:55 PM (18940 views) | In reply to jowolfe79

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;

View solution in original post

8 Likes Reply 15 REPLIES 15 PaigeMiller Diamond | Level 26 PaigeMiller Diamond | Level 26

Re: Easy way to calculate Cohen's d

Posted 03-09-2022 11:44 AM (18973 views) | In reply to jowolfe79

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 0 Likes Reply jowolfe79 Calcite | Level 5 jowolfe79 Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 03-09-2022 12:37 PM (18948 views) | In reply to jowolfe79

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 = (M2 - M1) SDpooled

SDpooled = √((SD12 + SD22) ⁄ 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;

0 Likes Reply jowolfe79 Calcite | Level 5 jowolfe79 Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 03-09-2022 12:52 PM (18942 views) | In reply to jowolfe79

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 = (M2 - M1) SDpooled

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

0 Likes Reply Rick_SAS SAS Super FREQ Rick_SAS SAS Super FREQ

Re: Easy way to calculate Cohen's d

Posted 03-09-2022 12:55 PM (18941 views) | In reply to jowolfe79

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; 8 Likes Reply jowolfe79 Calcite | Level 5 jowolfe79 Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 03-09-2022 01:06 PM (18934 views) | In reply to Rick_SAS Thank you so much!!! This is exactly what I needed. 0 Likes Reply mailgraceyang Calcite | Level 5 mailgraceyang Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 09-14-2022 04:00 AM (17781 views) | In reply to Rick_SAS

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

0 Likes Reply Ksharp Super User Ksharp Super User

Re: Easy way to calculate Cohen's d

Posted 09-14-2022 07:48 AM (17768 views) | In reply to mailgraceyang Make a new variable diff=after-before;and use this variable to book in Rick's code . 0 Likes Reply mailgraceyang Calcite | Level 5 mailgraceyang Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 09-14-2022 08:28 AM (17761 views) | In reply to Ksharp

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;

0 Likes Reply Ksharp Super User Ksharp Super User

Re: Easy way to calculate Cohen's d

Posted 09-14-2022 08:34 AM (17757 views) | In reply to mailgraceyang OK. It looks right.Also Could try this one :var Height;---->var diff; 0 Likes Reply mailgraceyang Calcite | Level 5 mailgraceyang Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 09-14-2022 08:37 AM (17756 views) | In reply to Ksharp thank you. 🙂 0 Likes Reply cl5 Calcite | Level 5 cl5 Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 04-19-2023 06:33 AM (15735 views) | In reply to Rick_SAS thanks for the solution!is there any way to request that SAS consider adding this as an option in proc glm or mixed? 0 Likes Reply TCSMITH5 Calcite | Level 5 TCSMITH5 Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 01-18-2024 09:23 PM (12801 views) | In reply to Rick_SAS

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

0 Likes Reply Ksharp Super User Ksharp Super User

Re: Easy way to calculate Cohen's d

Posted 01-18-2024 09:51 PM (12793 views) | In reply to TCSMITH5

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)

0 Likes Reply TCSMITH5 Calcite | Level 5 TCSMITH5 Calcite | Level 5

Re: Easy way to calculate Cohen's d

Posted 01-18-2024 10:41 PM (12776 views) | In reply to Ksharp

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;

0 Likes Reply
  • Previous
    • 1
    • 2
  • Next

sas-innovate-2026-white.png

April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.Register now and lock in 2025 pricing—just $495!

Register now

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.

Watch What is ANOVA? on YouTube

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 15 replies
  • ‎03-09-2022 11:32 AM
  • 18989 views
  • 9 likes
  • 7 in conversation
    • PaigeMiller
    • Rick_SAS
    • Ksharp
    • TCSMITH5
    • mailgraceyang
    • cl5
    • jowolfe79
Powered by Khoros

Tag » Cohen's D Effect Size Sas