Hello,
I am trying to run a 2 sample ttest over a dataset using the code below:
proc ttest data=dataset COCHRAN;
class class_var;
by dependent_var;
run;
However, I am getting the error "The CLASS variable dopes not have two levels."
I have filtered the data set such that only two values can exist for class_var; I have run a proc freq statement to ensure that only two values (and none missing) exist for the variable; I have even coded an indicator that can only take two values to use instead of class_var. The same error pops up in every case.
Any idea what I can try to do differently?
CLASS separates the groups for each BY level. You haven't specified an analysis variable, which would default to all numeric variables I believe.
To verify you actually have the groups you need two levels in each BY group, so your proc freq should really be something like the following to confirm your claim of two levels in all groups:
proc freq data=dataset;
table class_var*dependent_var;
run;
Or perhaps you're not quite doing the T-Test right and this is what you want:
proc ttest data=dataset COCHRAN;
class class_var;
Var dependent_var;
run;
@BozJ3 wrote:
Hello,
I am trying to run a 2 sample ttest over a dataset using the code below:
proc ttest data=dataset COCHRAN;
class class_var;
by dependent_var;
run;
However, I am getting the error "The CLASS variable dopes not have two levels."
I have filtered the data set such that only two values can exist for class_var; I have run a proc freq statement to ensure that only two values (and none missing) exist for the variable; I have even coded an indicator that can only take two values to use instead of class_var. The same error pops up in every case.
Any idea what I can try to do differently?
CLASS separates the groups for each BY level. You haven't specified an analysis variable, which would default to all numeric variables I believe.
To verify you actually have the groups you need two levels in each BY group, so your proc freq should really be something like the following to confirm your claim of two levels in all groups:
proc freq data=dataset;
table class_var*dependent_var;
run;
Or perhaps you're not quite doing the T-Test right and this is what you want:
proc ttest data=dataset COCHRAN;
class class_var;
Var dependent_var;
run;
@BozJ3 wrote:
Hello,
I am trying to run a 2 sample ttest over a dataset using the code below:
proc ttest data=dataset COCHRAN;
class class_var;
by dependent_var;
run;
However, I am getting the error "The CLASS variable dopes not have two levels."
I have filtered the data set such that only two values can exist for class_var; I have run a proc freq statement to ensure that only two values (and none missing) exist for the variable; I have even coded an indicator that can only take two values to use instead of class_var. The same error pops up in every case.
Any idea what I can try to do differently?
I feel really dumb now haha. That was indeed the issue. I misread the documentation.
Thank you for dealing kindly and swiftly with my error!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.