BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
fengyuwuzu
Pyrite | Level 9

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.

 

1 ACCEPTED SOLUTION

Accepted Solutions
Rick_SAS
SAS Super FREQ

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

3 REPLIES 3
ballardw
Super User

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; 

Rick_SAS
SAS Super FREQ

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;
fengyuwuzu
Pyrite | Level 9

Thank you, Rick!

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is ANOVA?

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.

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