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
The LSMEANS command in PROC GLM gives much more interpretable results.
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.
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..
Kon | 1 | 126.0250000 | 126.0250000 | 0.80 | 0.3852 |
Treat | 1 | 387.6568182 | 387.6568182 | 2.46 | 0.1376 |
Kon | 1 | 84.6568182 | 84.6568182 | 0.54 | 0.4748 |
Treat | 1 | 387.6568182 | 387.6568182 | 2.46 | 0.1376 |
In PROC GLM, add the LSMEANS statement, with whatever options you want;
lsmeans gender treat/tdiff;
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.
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;
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?
Intercept | -7.857818524 | B | 9.06399018 | -0.87 | 0.4006 | -27.29814401 | 11.582506960 |
Treat Cont | 8.641893762 | B | 6.20797873 | 1.39 | 0.1856 | -4.672896387 | 21.956683911 |
Treat Int | 0.000000000 | B | . | . | . | . | . |
Kon F | -3.063476648 | B | 6.43129427 | -0.48 | 0.6412 | -16.85723099 | 10.730277699 |
Kon M | 0.000000000 | B | . | . | . | . | . |
PreDD | 0.878227976 | 0.18708534 | 4.69 | 0.0003 | 0.476969834 | 1.279486118 |
The LSMEANS command in PROC GLM gives much more interpretable results.
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
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;
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.
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
I provided the proper LSMEANS statement in message 4 of this thread.
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!
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.
Ready to level-up your skills? Choose your own adventure.