BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
DougHold
Obsidian | Level 7

I came across this macro for calculating various effect size statistics, but I am unsure how to use it. Can someone show me how I would input in my data and run this? 

 

For example, I would like to compute Cohen's d and Hedges' g. My values are the following:

NE = 103
NC = 100
ME = 1.44
MC = 1.43
SE = 0.65
SC = 0.59

 

 

%macro compeff(indata,outdata);
/******************************************************/
/*  INDATA: Name of the Input Data Set                */
/*  OUTDATA: Name of the Output Data Set              */
/******************************************************/
data &outdata; set &indata;
/******************************************************/
/* INPUT DATA:                                        */
/*  NE:  Sample size for Experimental Group           */
/*  NC:  Sample size for Control Group                */
/*  ME:  Treatment Effect for Experimental Group      */
/*  MC:  Treatment Effect for Control Group           */
/*  SE:  Standard Deviation for Experimental Group    */
/*  SC:  Standard Deviation for Control Group         */
/*                                                    */
/* OUTPUT DATA:                                       */
/*  TYPE:  0 = Glass' Delta                           */
/*         1 = Cohen's d                              */
/*         2 = Hedges' g                              */
/*         3 = Hedges' gu                             */
/*         4 = Transformed Correlation rpb            */
/*  ESTIMATE: Effect-Szie Estimate                    */
/*  STD: Estimated Standard deviation                 */
/*  LOWER:  Lower Bound of 95% Confidence Interval    */
/*  UPPER:  Upper Bound of 95% Confidence Interval    */
/******************************************************/
   dfd = ne+nc;
   dfg = dfd-2;
/******************************************************/
/*  Compute Glass's Delta                             */
/******************************************************/
   del = (me-mc)/sc;
   vdel = dfd/(ne*nc)+(del*del)/(2*nc-2);
   sdel = sqrt(vdel);
/******************************************************/
/*  Compute Cohen's d                                 */
/******************************************************/
   sm = sqrt(((ne-1)*(se*se)+(nc-1)*(sc*sc))/dfd);
   dd = (me-mc)/sm;
   vdd = dfd/(ne*nc)+0.5*dd*dd/dfg;
   sdd = sqrt(vdd);
/******************************************************/
/*  Compute Hedges' g                                 */
/******************************************************/
   sp = sqrt(((ne-1)*(se*se)+(nc-1)*(sc*sc))/dfg);
   gg = (me-mc)/sp;
   vgg = dfd/(ne*nc)+0.5*gg*gg/dfg;
   sgg = sqrt(vgg);
/******************************************************/
/*  Compute Hedges' gu                                */
/******************************************************/
   corrf=exp(lgamma(0.5*dfg)-lgamma(0.5*(dfg-1))
      -log(sqrt(0.5*dfg)));
   gu = gg * corrf;
   vgu = dfd/(ne*nc)+0.5*gu*gu/dfd;
   sgu = sqrt(vgu);
/*********************************************************/
/*  Compute Point-Biserial Correlation                   */
/*********************************************************/
   rpb = sqrt((ne*nc*dd*dd)/(ne*nc*dd*dd+dfd*dfd));
   zrpb = 0.5*log((1+rpb)/(1-rpb));
   vzrpb = 1 / (dfd-3);
   szrpb = sqrt(vzrpb);
   type = 0;
   estimate = del;
   std = sdel;
   lower = del + probit(0.025) * sdel;
   upper = del + probit(0.975) * sdel;
   output;
   type = 1;
   estimate = dd;
   std = sdd;
   lower = dd + probit(0.025) * sdd;
   upper = dd + probit(0.975) * sdd;
   output;
   type = 2;
   estimate = gg;
   std = sgg;
   lower = gg + probit(0.025) * sgg;
   upper = gg + probit(0.975) * sgg;
   output;
   type = 3;
   estimate = gu;
   std = sgu;
   lower = gu + probit(0.025) * sgu;
   upper = gu + probit(0.975) * sgu;
   output;
   type = 4;
   estimate = rpb;
   std = szrpb;
   lower = zrpb + probit(0.025) * szrpb;
   upper = zrpb + probit(0.975) * szrpb;
   lower = (exp(2*lower)-1)/(exp(2*lower)+1);
   upper = (exp(2*upper)-1)/(exp(2*upper)+1);
   output;
   keep ne nc me mc se sc type estimate lower upper;
%mend compeff;

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
Kurt_Bremser
Super User

You need to create a dataset according to the description in the comment section:

/* INPUT DATA:                                        */
/*  NE:  Sample size for Experimental Group           */
/*  NC:  Sample size for Control Group                */
/*  ME:  Treatment Effect for Experimental Group      */
/*  MC:  Treatment Effect for Control Group           */
/*  SE:  Standard Deviation for Experimental Group    */
/*  SC:  Standard Deviation for Control Group         */

Like

data in;
input ne nc me mc se sc;
datalines;
103 100 1.44 1.43 0.65 0.59
;

View solution in original post

2 REPLIES 2
Kurt_Bremser
Super User

You need to create a dataset according to the description in the comment section:

/* INPUT DATA:                                        */
/*  NE:  Sample size for Experimental Group           */
/*  NC:  Sample size for Control Group                */
/*  ME:  Treatment Effect for Experimental Group      */
/*  MC:  Treatment Effect for Control Group           */
/*  SE:  Standard Deviation for Experimental Group    */
/*  SC:  Standard Deviation for Control Group         */

Like

data in;
input ne nc me mc se sc;
datalines;
103 100 1.44 1.43 0.65 0.59
;
DougHold
Obsidian | Level 7
Perfect, thank you!

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

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 2748 views
  • 0 likes
  • 2 in conversation