- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thank you, Rick!