BookmarkSubscribeRSS Feed
PCrider
Calcite | Level 5
I have data concerning semester grades and GPAs. one variable is credits (contains the number of credits a class is worth) and another variable grade (contains the letter grade that was received in the class). I want to create a new variable using arrays that would be GPA (number of credits for a specific class*grade received in that class(i.e. 4.0 for an A, 3.7 for an A-, 3.4 for a B+, etc...). Does that make sense? Here is some sample data:

Class Credits LetterGrade

STAT 361 3.0 C
STAT 536 3.0 B+
ENGL 251 3.0 B
HLTH 129 1.0 D+
PE D 190 0.5 B+
PE D 270 1.0 B
PE D 478R 1.0 A-
PE S 129 0.5 A
2 REPLIES 2
Cynthia_sas
SAS Super FREQ
Hi:
Where do you envision using an ARRAY??? Are you thiinking of using an array construct for the lookup of the letter grade to the GPA??? In your case, I'd use a format for doing the lookup.

The format technique is shown on page 6 of this paper:
http://www2.sas.com/proceedings/forum2008/095-2008.pdf (and there are comparisons of other techniques as well)

This previous forum posting showed the use of a format to create a new variable:
http://support.sas.com/forums/thread.jspa?messageID=17511䑧 (at the bottom of the post)

cynthia
GeorgeLee
Calcite | Level 5
PCrider,

I don't think you'll need array for this. I agree with Cynthia on proc format. Below is a quick code I wrote, hope it helps. Don't forget to edit/complete the conversion list in proc format.

Best,

George
-----------------------------
proc format;
value $grade 'A' = 4 'A-' = 3.7 'B+' = 3.4 'B' = 3 'C+' = 2.3 'C' =2 'D+' = 1.3;
run;

data GPA;
infile 'H:\Personal\GPA.txt' dlm=',';
input coursenum $:9. credit :2. grade $:2.;
point_grade = put (grade, $grade.);
gpa = point_grade * credit;
run;

proc print data = gpa;
run;

sas-innovate-white.png

Missed SAS Innovate in Orlando?

Catch the best of SAS Innovate 2025 — anytime, anywhere. Stream powerful keynotes, real-world demos, and game-changing insights from the world’s leading data and AI minds.

 

Register now

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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