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

PROC TTEST DATA = HEART;

CLASS WEIGHT_STATUS;

VAR CHOLESTROL;

RUN;

  i AM GETTING AN ERROR SAYING CLASS HAS MORE THAN 2 LEVELS. i AM VERY NEW TO PROC TTEST, ANOVA , GLM ETC. i WAS PRACTICING IT AND FOUND THIS ERROR. i ACTUALLY CHECKED FOR MISSING VALUES TOO. CAN YOU PPLEASE GUIDE 

1 ACCEPTED SOLUTION

Accepted Solutions
FreelanceReinh
Jade | Level 19

Hello @GeetVish and welcome to the SAS Support Communities!

 

Try something like this:

 

proc ttest data = sashelp.heart;
where weight_status in ('Normal', 'Overweight');
class weight_status;
var cholesterol;
run;

I restricted weight_status to those two levels which seemed most interesting to me in view of the results of the PROC FREQ step below:

proc freq data=sashelp.heart;
tables weight_status;
run;

 

 

View solution in original post

5 REPLIES 5
PaigeMiller
Diamond | Level 26

If you are getting an error that says you have more than two levels, then the conclusion is obvious, your data used in PROC TTEST has more than two levels.

 

You need to examine the data set you are using, and you will see that there are more than two levels for the variable WEIGHT_STATUS.

 

Please DO NOT TYPE YOUR ENTIRE MESSAGE IN ALL CAPITALS. Use proper English mixed case. Thank you.

--
Paige Miller
GeetVish
Calcite | Level 5

ok thanks , i am very new to this blog too. Thanks anyways .I will check.

Can you tell me how to check the levels? what is level?

FreelanceReinh
Jade | Level 19

Hello @GeetVish and welcome to the SAS Support Communities!

 

Try something like this:

 

proc ttest data = sashelp.heart;
where weight_status in ('Normal', 'Overweight');
class weight_status;
var cholesterol;
run;

I restricted weight_status to those two levels which seemed most interesting to me in view of the results of the PROC FREQ step below:

proc freq data=sashelp.heart;
tables weight_status;
run;

 

 

PaigeMiller
Diamond | Level 26

@GeetVish wrote:

ok thanks , i am very new to this blog too. Thanks anyways .I will check.

Can you tell me how to check the levels? what is level?


If you don't know what a level is, how can you even consider doing a T-test? That's what a t-test does, it compares the means of two different levels (conditions, settings, etc.) of a variable (in this case WEIGHT_STATUS) in your data.

 

You can check the levels in any number of ways; by doing a PROC PRINT or a PROC FREQ on the variable WEIGHT_STATUS. It is also a very good idea to learn how to view your data to debug problems by viewing your data using the viewtable feature in SAS.

--
Paige Miller

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 5 replies
  • 2905 views
  • 6 likes
  • 4 in conversation