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

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;

1 ACCEPTED SOLUTION

Accepted Solutions
PGStats
Opal | Level 21

 

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

3 REPLIES 3
Reeza
Super User
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.
PGStats
Opal | Level 21

 

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
Jeffy_Poo24
Calcite | Level 5
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!

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to connect to databases in SAS Viya

Need to connect to databases in SAS Viya? SAS’ David Ghan shows you two methods – via SAS/ACCESS LIBNAME and SAS Data Connector SASLIBS – in this video.

Find more tutorials on the SAS Users YouTube channel.

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