Help using Base SAS procedures

how to use arrays

Reply
New Contributor
Posts: 4

how to use arrays

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
SAS Super FREQ
Posts: 8,744

Re: how to use arrays

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
N/A
Posts: 1

Re: how to use arrays

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;
Ask a Question
Discussion stats
  • 2 replies
  • 128 views
  • 0 likes
  • 3 in conversation