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

Hi,

 

I have a small randomised study with 10 patients in the intervention and 8 patients in the control group. I have one before and one after measurement on each patient.

I want to find out the mean differences between the groups on my outcomes and have created a new dataset with the differences and logged one of the variables (HbA1c) to get a more normal distribution of data.

 

data work.log;

set WORK.TTEST_0000;

 

class=treat;

lpreHbA1c=log2(preHbA1c);

lPostHbA1c=log2 (postHbA1c);

DDdif=preDD-PostDD;

HADSdif=preHADS-PostHADS;

HbA1cdif=lprehbA1c-lpostHba1c;

W5dif=pre_W5-Post_W5;

run;

 

I have run the t test:

 

Proc ttest Data=WORK.log;

class Treat;

Var DDdif HADSdif HbA1cdif W5dif;

Run;

 

But need to know the differences between genders in the two samples, but get an error when I inpute gender (called "Kon") in the class statement.

 

How should I input gender (Kon) to make the subgroup analysis ?

 

NB. I use SAS enterprise.

 

Thanks in advance.

BW,

Sophie

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

The LSMEANS command in PROC GLM gives much more interpretable results.

--
Paige Miller

View solution in original post

12 REPLIES 12
PaigeMiller
Diamond | Level 26

PROC TTEST allows only one variable in the CLASS statement.

 

It seems like you have a situation where the proper analysis is a paired analysis to compare before versus after, which you can achieve by computing differences before versus after, as you have done; or it can be done on the un-differenced data using the PAIRED statement. However, if you want to introduce gender into the analysis, this requires PROC GLM.

 

Example:

 

proc glm data=work.log;
    class gender treat;
    model dddif hadsdif hba1cdif w5dif = gender treat;
run;
quit;

Although this is not called a t-test, it is the logical and statistical equivalent of a t-test in the situation you described. 

--
Paige Miller
AnneSophie
Calcite | Level 5

Dear Paige Miller.

 

Thanks for your quick reply!

 

The GLM statement works, however, the difference for the two genders; men respectively women, seems to be missing in the output?

Or I might not interpret correctly..

 

Source DF Type I SS Mean Square F Value Pr > F
Kon1126.0250000126.02500000.800.3852
Treat1387.6568182387.65681822.46

0.1376

 

Source DF Type III SS Mean Square F Value Pr > F
Kon184.656818284.65681820.540.4748
Treat1387.6568182387.65681822.46

0.1376

 

I also get a Interaction plot for DDdif
 
Interactionplot_DDdif.JPG
PaigeMiller
Diamond | Level 26

In PROC GLM, add the LSMEANS statement, with whatever options you want;

 

lsmeans gender treat/tdiff;
--
Paige Miller
DWilson
Pyrite | Level 9

The proc glm code you have doesn't account for an interaction term. It won't capture the interaction between sex and outcome.

You could do: model outcome=sex treatment sex*treatment

 

but getting the test you want from that model is somewhat complicated.

DWilson
Pyrite | Level 9

It's not clear what you mean by differences in genders. If you are talking about analyzing males and females separately, just subset your data to males and run your proc ttest for them and then do another proc ttest for females.

 

If you are talking about a difference in differences sort of test: (mean for males - mean for females in control group) - (mean for males - mean for females in treatment group) then you need to set up something like proc glm (as recommended by another person) and use a contrast statment to construct that difference and get a t-test around it.

Let group takes on values 1 to 4;

group =1 if sex=male and treatment=control

group =2 if sex=male and treatment=treatment

group =3 if sex=female and treatment=control

group =4 if sex=female and treatment=treatment

 

 

Something like (key parts shown);

proc glm data=...;

class group;

model outcome=group / noint;

contrast 'Difference of Differences' group 1 -1 -1 1;

run;

 

AnneSophie
Calcite | Level 5

Dear DWilson.

Thanks for your comprehensive reply.

 

By differences in gender I mean;

If the effect of the intervention differs between men and women on all outcomes.

I need a mean + CL + p-value in the output for men AND women separately. (As the intervention had previously been reported to have a better effect in women) (Kon = gender)

 

Would this code give me that:

 

Proc glm data=work.log_new;

class treat Kon;

Model PostDD = treat kon PreDD/solution clparm;

run;

 

However, I'm not sure how to interpret the outcome?

 

 

Parameter Estimate   StandardError t Value Pr > |t| 95% Confidence Limits
Intercept-7.857818524B9.06399018-0.870.4006-27.2981440111.582506960
Treat Cont8.641893762B6.207978731.390.1856-4.67289638721.956683911
Treat Int0.000000000B.....
Kon F-3.063476648B6.43129427-0.480.6412-16.8572309910.730277699
Kon M0.000000000B.....
PreDD0.878227976 0.187085344.690.00030.4769698341.279486118

 

img0.png
PaigeMiller
Diamond | Level 26

The LSMEANS command in PROC GLM gives much more interpretable results.

--
Paige Miller
AnneSophie
Calcite | Level 5

Thanks, a lot for your advice.

I did the;

 

proc glm data=work.log;

class Kon treat;

by kon;

model PostDD= PreDD Kon treat/solution clparm;

lsmeans Kon treat/tdiff cl;

run;

 

And it worked for me.

I got the outcomes adjusted for baseline differences and sorted by gender.

Thanks a lot:-)

BW, Sophie

DWilson
Pyrite | Level 9

I think what you are asking is:

1) how to get the treatment effect for females

2) how to get the treatment effect for males

3) how to get the difference between the treatment effect for females and treatment effect for males

 

If so, I'd do this:

proc glm data=...;
class group;
model outcome=group / noint;
contrast 'Difference of Differences' group 1 -1 -1 1; /*if this is significant then the difference between treatment and control are different between males and females*/
contrast 'Male Effect' group 1 -1 0 0; /* if this is significant then the difference between treatment and control for males is significant */
contrast 'Female Effect' group 0 0 1 -1; /* if this is significant then the difference between treatment and control for females is significant */

run;

 

where

group =1 if sex=male and treatment=control

group =2 if sex=male and treatment=treatment

group =3 if sex=female and treatment=control

group =4 if sex=female and treatment=treatment

run;

 

DWilson
Pyrite | Level 9

There's probably a way to get the same estimates as with my contrast statements using LSMEANS and a GLM model like this:

 

class sex treat;

model outcome= sex treat sex*treat;

 

but I don't know them offhand.

AnneSophie
Calcite | Level 5

Thanks a lot, both of you. I tried the LSmeans statement, but I need to adjust for the baseline value also  (Theres some clinical important baseline differences, that might impact the potential reduction)

 

I was told that the statement below gives the mean for the overall group differences on Diabetes distress (DD).

Now I want to know if the overall differnce is driven by a better effect in men or women.

 

I attach my outcome table, which might give you an idea of what I need. (The results on sex are not correct).

 

Proc glm data=work.log;

class treat;

Model PostDD = PreDD/solution clparm;

run;

 

I think it might be a quite simple procedure - to you;-) I'm just a novice in SAS..

 

Is I should use lsmeans, where in the statement should I put it. But importantly, I need to adjust for the baseline (preDD).

Thanks Again.

BW. Anne Sophie

PaigeMiller
Diamond | Level 26

I provided the proper LSMEANS statement in message 4 of this thread.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 12 replies
  • 1857 views
  • 0 likes
  • 3 in conversation