Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- SAS Procedures
- /
- How to include 2 categorial variables in a Two sample t test

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** and **locked**.
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 05-08-2019 06:57 AM
(692 views)

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

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

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

--

Paige Miller

Paige Miller

12 REPLIES 12

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

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

Paige Miller

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

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

Kon | 1 | 126.0250000 | 126.0250000 | 0.80 | 0.3852 |

Treat | 1 | 387.6568182 | 387.6568182 | 2.46 | 0.1376 |

Source DF Type III SS Mean Square F Value Pr > F

Kon | 1 | 84.6568182 | 84.6568182 | 0.54 | 0.4748 |

Treat | 1 | 387.6568182 | 387.6568182 | 2.46 | 0.1376 |

I also get a Interaction plot for DDdif

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

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

`lsmeans gender treat/tdiff;`

--

Paige Miller

Paige Miller

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

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.

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

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;

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

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.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 |

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

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

--

Paige Miller

Paige Miller

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

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

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

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;

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

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.

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

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

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

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

--

Paige Miller

Paige Miller

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

**If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. **

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.