SAS Data Integration Studio, DataFlux Data Management Studio, SAS/ACCESS, SAS Data Loader for Hadoop and others

Trying to perform a chi squared test.

Accepted Solution Solved
Reply
New Contributor
Posts: 2
Accepted Solution

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
Respected Advisor
Posts: 4,919

Re: Trying to perform a chi squared test.

[ Edited ]
Posted in reply to Jeffy_Poo24

 

Your code shows that you have mastered many important techniques already.

 

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

View solution in original post


All Replies
Super User
Posts: 19,768

Re: Trying to perform a chi squared test.

Posted in reply to Jeffy_Poo24
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
Respected Advisor
Posts: 4,919

Re: Trying to perform a chi squared test.

[ Edited ]
Posted in reply to Jeffy_Poo24

 

Your code shows that you have mastered many important techniques already.

 

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

Re: Trying to perform a chi squared test.

Posted in reply to Jeffy_Poo24
Ah, thank you very much! I knew I had to group the GPA's together at some point, I just didn't know how or where to do it. Thank you very much!
🔒 This topic is solved and locked.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 376 views
  • 2 likes
  • 3 in conversation