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

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? 

87 /* Test for normality */
88 proc univariate data=WORK.COFFEE normal mu0=0;
89 ods select TestsForNormality;
90 class After;
91 var Before;
92 run;
93
94 /* t test */
95 proc ttest data=WORK.COFFEE sides=2 h0=0 plots(showh0);
96 class After;
97 var Before;
98 run;
1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

11 REPLIES 11
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Vcalderon233
Calcite | Level 5
Can you clarify what you mean by "levels"? I think may be the source of my confusion. In the spreadsheet I used for the data set, there are only two columns. One labeled "Before" and the other "After". Also, those are the only two variable options
PaigeMiller
Diamond | Level 26

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.

--
Paige Miller
Vcalderon233
Calcite | Level 5
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
PaigeMiller
Diamond | Level 26

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

 

 

--
Paige Miller
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
Vcalderon233
Calcite | Level 5

Thank you for providing this clarification. This appeared to resolve the issue.

PaigeMiller
Diamond | Level 26

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

--
Paige Miller
Vcalderon233
Calcite | Level 5
That is aligned with what I was looking for, I appreciate you sharing this resource.
tom_grant
SAS Super FREQ

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:

 
/* t test */
proc ttest data=SASHELP.CLASS sides=2 h0=0 plots(showh0);
class Sex;
var Height;
run;
Vcalderon233
Calcite | Level 5
Thank you for providing this reference point. This helped me contextualize the feedback.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

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
  • 11 replies
  • 1624 views
  • 2 likes
  • 3 in conversation