In addition to the suggestions you have already received, I think you may want to give the problem a little more thought.
For example, you don't include F in your grade format. Shouldn't it get a value of 0 rather than a missing value?
And are all grades counted in the calculation of the GPA? Don't some/most schools omit grades like pass, no pass, withdraw, transfer and incomplete?
As such, I think you might want something closer to:
DATA GPAStats (KEEP = TCreditHrs TGradePts GPA STUDENT_ID);
SET test.analysts_grades;
BY STUDENT_ID;
RETAIN TGPACreditHrs 0 TCreditHrs 0 TGradePts 0 GPA 0;
SELECT(GRADE);
WHEN('A') GradePts = 4;
WHEN('B') GradePts = 3;
WHEN('C') GradePts = 2;
WHEN('D') GradePts = 1;
WHEN('F') GradePts = 0;
OTHERWISE GradePts = .;
END;
if first.STUDENT_ID then do;
call missing(TCreditHrs);
call missing(TGradePts);
call missing(TGPACreditHrs);
end;
TCreditHrs+CREDIT_HR;
if not missing(GradePts) then do;
TGPACreditHrs+CREDIT_HR;
TGradePts+ (GradePts * CREDIT_HR);
end;
if last.STUDENT_ID then do;
GPA = TGradePts / TGPACreditHrs;
output;
end;
RUN;
Art, CEO, AnalystFinder.com
... View more