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
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
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....
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
thanks 🙂
yea I can't seem to find an easier way than that either.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.