BookmarkSubscribeRSS Feed
cneed
Obsidian | Level 7

Hello! How can I get the average GPA for the students in my file Data.master_After2001? GPA is calculated as the sum of grades/number of courses and grades can be summed by assigning A=4, B=3, C=2, D=1, and F=0.

 

data.master_after2001.PNG

 

 

I have a file to join called Data.grades:

 

Data.grades.PNG

 

Each student may have more then one course taken. What would the code be for the average GPA and can I get the average GPA split out by males and females?

 

Thanks!

4 REPLIES 4
Reeza
Super User

1. Recode letters to numeric values

2. Merge the two data sets such that gender is brought into the second data set

3. Summarize

 

data table2_recoded;
set table2;

if grade='F' then grade_value=0;
else if grade='D' then grade_value = 1;
....


run;

proc sort data=table2_recoded;
by studentID; run;
proc sort data=table1; 
by studentID; run;

data table12;
merge table2_recoded table1 (keep = studentID gender);
by studentID;

run;

proc means data=table12 STACKODS N MEAN MAX MEDIAN MIN;
class gender;
var grade_value;
ods output summary=SummaryStats;
run;

@cneed wrote:

Hello! How can I get the average GPA for the students in my file Data.master_After2001? GPA is calculated as the sum of grades/number of courses and grades can be summed by assigning A=4, B=3, C=2, D=1, and F=0.

 

data.master_after2001.PNG

 

 

I have a file to join called Data.grades:

 

Data.grades.PNG

 

Each student may have more then one course taken. What would the code be for the average GPA and can I get the average GPA split out by males and females?

 

Thanks!


 

cneed
Obsidian | Level 7

Thanks for the reply! How can I make it so that the GPA is another row in the Data.master_After2001 file? Your code is giving me a means table but I want the gpa to apart of the first file of 5,000 students. This is what your code is giving me an output of:

 

Output.PNG

Reeza
Super User
Did you check every table generated? That's just one of the tables, and you didn't show the name so I can't even tell you which one. table12 should have everything in it you want.
cneed
Obsidian | Level 7

Both the new tables were giving me that output. My first original file of students (Data.master_After2001) has 5,000 students my 2nd original file of grades (Data.grades) has over 1,000,000 lines as each student has more then one grade. I am looking to convert the grades to A=4, B=3, C=2, D=1, and F=0, sum them up for each student then divide them by the number of courses taken (how many grades supplied for each student) to find the gpa for each student. In total the file should be 5,000 rows but is currently over 1,000,000 with the code provided. 

 

data Data.grades_recoded;
set Data.grades;

if grade='F' then grade_value=0;
else if grade='D' then grade_value = 1;
else if grade='C' then grade_value = 2;
else if grade='B' then grade_value = 3;
else if grade='A' then grade_value = 4;

RUN;

PROC SORT DATA=Data.grades_recoded;
by studentID;
RUN;
PROC SORT DATA=Data.master_After2001;
by studentID;
RUN;

data Data.master_GPA;
merge Data.grades_recoded Data.master_After2001 (keep = studentID gender);
by studentID;

RUN;

PROC MEANS DATA=Data.master_GPA STACKODS N MEAN MAX MEDIAN MIN;
class gender;
var grade_value;
ods output summary=SummaryStats;
RUN;

 

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 1071 views
  • 0 likes
  • 2 in conversation