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.
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;
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;
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;
Thank you, Rick!
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
ANOVA, or Analysis Of Variance, is used to compare the averages or means of two or more populations to better understand how they differ. Watch this tutorial for more.
Find more tutorials on the SAS Users YouTube channel.