I am attempting to run a two-sample test with a data set imported from an excel sheet. There are two values of data, Before and After, that I am attempting to compare. When I input the information, I am receiving a log error "ERROR: The CLASS variable has more than two levels." Can someone support with what is missing?
Perhaps you are trying to test (using PROC TTEST) if the mean of Before is equal to the mean of AFTER. Is that what you want to do?
If so, your data set needs to be arranged like this (where the first row is the variable names). You obviously don't have this and so PROC TTEST can't run on your data.
WHEN SCORE BEFORE 22.2 BEFORE 23.9 AFTER 15.0 AFTER 21.7 AFTER 19.8
In this case
proc ttest data=have;
var score;
class when;
run;
If you have more than two levels, then PROC TTEST will not work, and produces the error you show. PROC TTEST will only work if variable AFTER has exactly two levels. Please look at your SAS data set named WORK.COFFEE to see what is variable AFTER.
Let's not talk about Excel. This has everything to do with the SAS data set you have named WORK.COFFEE. Please look at it with your own eyes. Levels is another way of saying distinct values.
@Vcalderon233 wrote:
I have looked at it in the data set, which again, is the source of my confusion. When I look at the SAS data set, the variable listed are 2. Where can I look in the data set to find distinct values
You count the distinct values in the variable named AFTER. You can do this visually.
Perhaps you are trying to test (using PROC TTEST) if the mean of Before is equal to the mean of AFTER. Is that what you want to do?
If so, your data set needs to be arranged like this (where the first row is the variable names). You obviously don't have this and so PROC TTEST can't run on your data.
WHEN SCORE BEFORE 22.2 BEFORE 23.9 AFTER 15.0 AFTER 21.7 AFTER 19.8
In this case
proc ttest data=have;
var score;
class when;
run;
Thank you for providing this clarification. This appeared to resolve the issue.
Perhaps (I'm guessing) what you really want is a Paired T-test. Is that what you want? Then you need a different layout of the data, possibly even the layout you have already. See this example
I am guessing you have two columns (variables - Before & After) with some kind of measurement as the values.
You need to have two columns (variables - for example Stage with values "Before" and "After" & Measurements - with the measurement values)
Here is an example with sashelp.class data:
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Ready to level-up your skills? Choose your own adventure.