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

ttest freq table.PNG

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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:

ttest freq table.PNG

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?


 

View solution in original post

2 REPLIES 2
Reeza
Super User

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:

ttest freq table.PNG

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?


 

BozJ3
Fluorite | Level 6

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!

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

Register now!

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

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

View all other training opportunities.

Discussion stats
  • 2 replies
  • 4997 views
  • 0 likes
  • 2 in conversation