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.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

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