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!
Don't miss out on SAS Innovate - Register now for the FREE Livestream!
Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.
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.