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

is there any way to do proc ttest on multiple variables. for instance:

I have a dataset with variables :

 

subjid include _1_abc_q1   _1_abc_q2  _1_abc_q3_8_abc_q1 _8_abc_q2  _8_abc_q3

   1        1            6                    4                  3               5                4                  3

   2        1            6                    1                  3               6                4                 5

 

 

and I want to do paired ttest for _1_abc_q1*_8_abc_q1 

                                                   _1_abc_q2*_8_abc_q2

                                                   _1_abc_q3*_8_abc_q3 

also can I get the means separately for each of the variables in the paired ttest in addition to the difference of the means (e.g., mean of _1_abc_q1 and mean of *_8_abc_q1)...keeping in mind that just doing a proc means on each variable would include observations not present in the paired ttest (due to missing observations in one of variables).

 

I do have another dataset that sets up the same data in another way so that the 1 and 8s are variables and the q1-q3 are variables if doing a ttest/means would be easier/ possible this way:

 

subjid   include        wk     q1    q2    q3

    1            1             1       6       4     3

    2            1              1       6      1     3

    1            1              8       5      4     3

    2           1               8       6       4    5

1 ACCEPTED SOLUTION

Accepted Solutions
art297
Opal | Level 21

I don't know of an easy way. You could always use something like:

 

data data1;
  input subjid include _1_abc_q1   _1_abc_q2  _1_abc_q3 _8_abc_q1 _8_abc_q2  _8_abc_q3;
  cards;
1     1     6    4     3    5    4   3
2     1     6    1     3    6    4   5
;

proc ttest data=data1;
  paired _1_abc_q1*_8_abc_q1 _1_abc_q2*_8_abc_q2 _1_abc_q3*_8_abc_q3;
run;

proc means data=data1 (where=((not missing(_1_abc_q1)) and (not missing(_8_abc_q1))));
  var _1_abc_q1 _8_abc_q1;
run;

proc means data=data1 (where=((not missing(_1_abc_q2)) and (not missing(_8_abc_q2))));
  var _1_abc_q2 _8_abc_q2;
run;

proc means data=data1 (where=((not missing(_1_abc_q3)) and (not missing(_8_abc_q3))));
  var _1_abc_q3 _8_abc_q3;
run;

Art, CEO, AnalystFinder.com

View solution in original post

3 REPLIES 3
starz4ever2007
Quartz | Level 8

I was able to get the t tests to run using:

 

proc ttest data=data1;

paired ( _1_abc: ) : ( _8_abc: );

run;

 

but still unable to figure out how to get the separate means....

art297
Opal | Level 21

I don't know of an easy way. You could always use something like:

 

data data1;
  input subjid include _1_abc_q1   _1_abc_q2  _1_abc_q3 _8_abc_q1 _8_abc_q2  _8_abc_q3;
  cards;
1     1     6    4     3    5    4   3
2     1     6    1     3    6    4   5
;

proc ttest data=data1;
  paired _1_abc_q1*_8_abc_q1 _1_abc_q2*_8_abc_q2 _1_abc_q3*_8_abc_q3;
run;

proc means data=data1 (where=((not missing(_1_abc_q1)) and (not missing(_8_abc_q1))));
  var _1_abc_q1 _8_abc_q1;
run;

proc means data=data1 (where=((not missing(_1_abc_q2)) and (not missing(_8_abc_q2))));
  var _1_abc_q2 _8_abc_q2;
run;

proc means data=data1 (where=((not missing(_1_abc_q3)) and (not missing(_8_abc_q3))));
  var _1_abc_q3 _8_abc_q3;
run;

Art, CEO, AnalystFinder.com

starz4ever2007
Quartz | Level 8

thanks 🙂

 

yea I can't seem to find an easier way than that either.

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 3 replies
  • 928 views
  • 1 like
  • 2 in conversation