Help using Base SAS procedures

Proc Ttest Error: The CLASS variable does not have two levels.

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 9
Accepted Solution

Proc Ttest Error: The CLASS variable does not have two levels.

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?


Accepted Solutions
Solution
‎02-02-2018 03:33 PM
Super User
Posts: 23,724

Re: Proc Ttest Error: The CLASS variable does not have two levels.

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


All Replies
Solution
‎02-02-2018 03:33 PM
Super User
Posts: 23,724

Re: Proc Ttest Error: The CLASS variable does not have two levels.

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?


 

Occasional Contributor
Posts: 9

Re: Proc Ttest Error: The CLASS variable does not have two levels.

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!

☑ This topic is solved.

Need further help from the community? Please ask a new question.

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