I would like to compare mean values of two groups using proc ttest
, and I successfully did it as below.
proc ttest;
class group;
var score;
run;
But, this code just assumes observations with group = 0
as the default group. So, the t-statistics
is calculated based on Mean
(score of obs with group= 0) minus Mean (score of obs with group= 1). But, I would like to have it the other way around.
It would just change the sign of t-statistics
, but it's just what I wanted to do.
Is there an option to do so by simply adding an option?
I know I could have done it if I have made another dummy variable which is exactly the opposite of my group variable. But, I don't want to create more dummy variables.
ORDER=DATA
will tell SAS to order the class variable based on when it encounters the values. So if the 1
values are earlier than the 0
values, it will be first in the comparison.
For example:
data for_ttest;
call streaminit(7);
do group = 0 to 1;
do _n_ = 1 to 50;
score = rand('NORMAL',1,0.5)+group;
output;
end;
end;
run;
proc sort data=for_ttest;
by descending group;
run;
proc ttest data=for_ttest order=data;
class group;
var score;
run;
Without ORDER=DATA
, it behaves as you saw, but with it, 1 is the first group.
You could also combine ORDER=FORMATTED
with a format.
proc format;
value groupf
1="Group 1 (Value=1)"
0="Group 2 (Value=0)"
;
quit;
proc ttest data=for_ttest order=formatted;
class group;
format group groupf.;
var score;
run;
The labels in the PROC FORMAT
are irrelevant, other than that they must be alphabetically sorted. Unfortunately the PRELOADFMT
option is not available in PROC TTEST
, so you can't use the NOTSORTED
trick in PROC FORMAT
to allow this to work even with the original values (though you can use non-printing characters to mess with sort order if you really want to).