Programming the statistical procedures from SAS

paired t-test for a group of variables

Accepted Solution Solved
Reply
Super Contributor
Posts: 312
Accepted Solution

paired t-test for a group of variables

I have data in the following structure:

ID var1 var2 var3 when

1 10 15 20 After

1 9 14 18 Before

2 12 17 21 After

2 11 17 20 Before

3 10 16 23 After

3 11 15 22 Before

4 8 18 24 After

4 9 17 23 Before

...

If I want to do a paired t-test for each variable, it seems I need to create 3 datasets, one for each variable.

Is there simpler way to do it?

 

Thanks.

 


Accepted Solutions
Solution
‎05-25-2016 04:59 PM
SAS Super FREQ
Posts: 3,306

Re: paired t-test for a group of variables

I think the simpler way to to combine each pair of rows. Basically moving from a "long form" of data that hass 3 measurements to a "wide form" that has 6 measurements.

 

If you strategically name the "before"  and "after" variables, you can run all three analyses with a single PROC TTEST call:

 

data have2;
input ID 
      after_var1  after_var2 after_var3
      before_var1 before_var2 before_var3;
datalines;
1 10 15 20 9 14 18
2 12 17 21 11 17 20
3 10 16 23 11 15 22
4 8 18 24  9 17 23 
;

proc ttest data=have2;
paired (after:):(before:);
run;

View solution in original post


All Replies
Grand Advisor
Posts: 10,043

Re: paired t-test for a group of variables

You would need to create one data set with the structure of:

Id BeforeVar1 AfterVar1 BeforeVar2 AfterVar2 BeforeVar3 AfterVar3.

 

Then the syntax would be:

Proc ttest data=have;

   Paired BeforeVar1 * AfterVar1    BeforeVar2 * AfterVar2   BeforeVar3 * AfterVar3;

run; 

Solution
‎05-25-2016 04:59 PM
SAS Super FREQ
Posts: 3,306

Re: paired t-test for a group of variables

I think the simpler way to to combine each pair of rows. Basically moving from a "long form" of data that hass 3 measurements to a "wide form" that has 6 measurements.

 

If you strategically name the "before"  and "after" variables, you can run all three analyses with a single PROC TTEST call:

 

data have2;
input ID 
      after_var1  after_var2 after_var3
      before_var1 before_var2 before_var3;
datalines;
1 10 15 20 9 14 18
2 12 17 21 11 17 20
3 10 16 23 11 15 22
4 8 18 24  9 17 23 
;

proc ttest data=have2;
paired (after:):(before:);
run;
Super Contributor
Posts: 312

Re: paired t-test for a group of variables

Thank you, Rick!

☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 179 views
  • 0 likes
  • 3 in conversation