Solved
New Contributor
Posts: 2

# Trying to perform a chi squared test.

Okay, this is my first post, I am new to this SAS stuff. This is a required course for my major and I am not really good at it. I was hoping you guys could help me out.

I am stuck on the first problem coding part. I can't seem to get the chi squared test to work. It would be greatly appreciated if you could help me. This is my code that isn't correct obviously:

proc format;

value \$EvaluationOfInstructor 'E'= 'Excellent' 'G'='Good' 'A'='Average' 'P'='Poor';

title GPA of the Student vs Evaluation of the Instructor;

data mylib.Project2GPA;

input EvaluationOfInstructor \$ Below Between Above;

format EvaluationOfInstructor \$EvaluationOfInstructor.;

datalines;

E 18 33 37

G 17 27 43

A 21 31 23

P 25 14 11

;

run;

proc freq data=mylib.project2gpa2;

tables EvaluationOfInstructor*GPAofStudent / chisq measures;

run;

data mylib.project2gpa2;

set mylib.project2gpa;

label

Below = 'Below 2.5'

Between = '2.5 to 3.5'

Above = 'Above 3.5';

run;

data mylib.project2gpa3;

set mylib.project2gpa2;

label

Below = 'GPAofStudent'

Between = 'GPAofStudent'

Above = 'GPAofStudent';

run;

Accepted Solutions
Solution
‎11-10-2015 05:32 AM
Posts: 5,482

## Re: Trying to perform a chi squared test.

[ Edited ]

The key point you are missing is that the columns Below, Between and Above all represent the same variable (number of students) in different classes (of GPA). SAS procedures expect classes to be represented by class variables.

In the example below, I rearranged the data in columns Evaluation, GPA, and NbStudents. That's what proc FREQ is expecting.

``````proc format;
value \$Evaluation
'E'='Excellent'
'G'='Good'
'A'='Average'
'P'='Poor';
run;

title "GPA of the Student vs Evaluation of the Instructor";

data Project2GPA;
length GPA \$10 Evaluation \$1;
input Evaluation \$ @;
do GPA = 'Below 2.5', '2.5 to 3.5', 'Above 3.5';
input nbStudents @;
output;
end;
label
GPA="GPA of the Student"
Evaluation="Evaluation given to Instructor";
format Evaluation \$Evaluation.;
datalines;
E 18 33 37
G 17 27 43
A 21 31 23
P 25 14 11
;

proc freq data=Project2GPA;
tables GPA*Evaluation / chisq;
weight nbStudents;
run;``````

PG

All Replies
Super User
Posts: 23,342

## Re: Trying to perform a chi squared test.

Your proc freq refers to 1)a variable GPAofStudent that doesn't exist in your dataset 2) It refers to project2gpa2 while the data set imported is called project2gpa, no 2 at the end. Data in the proc freq statement refers to the input dataset.
Solution
‎11-10-2015 05:32 AM
Posts: 5,482

## Re: Trying to perform a chi squared test.

[ Edited ]

The key point you are missing is that the columns Below, Between and Above all represent the same variable (number of students) in different classes (of GPA). SAS procedures expect classes to be represented by class variables.

In the example below, I rearranged the data in columns Evaluation, GPA, and NbStudents. That's what proc FREQ is expecting.

``````proc format;
value \$Evaluation
'E'='Excellent'
'G'='Good'
'A'='Average'
'P'='Poor';
run;

title "GPA of the Student vs Evaluation of the Instructor";

data Project2GPA;
length GPA \$10 Evaluation \$1;
input Evaluation \$ @;
do GPA = 'Below 2.5', '2.5 to 3.5', 'Above 3.5';
input nbStudents @;
output;
end;
label
GPA="GPA of the Student"
Evaluation="Evaluation given to Instructor";
format Evaluation \$Evaluation.;
datalines;
E 18 33 37
G 17 27 43
A 21 31 23
P 25 14 11
;

proc freq data=Project2GPA;
tables GPA*Evaluation / chisq;
weight nbStudents;
run;``````

PG
New Contributor
Posts: 2