BookmarkSubscribeRSS Feed
jwestra84
Fluorite | Level 6

I have what is sort of like a transcript for classes with variables id, class, grade, credits, etc. Some of the classes are repeats within an id and I need to only count the class that was taken most recently in the GPA. Is there any way to not count the first of the repeats in the GPA, while still allowing the class to show on the transcript. I need to count the final class in the overall GPA.

Thanks!

2 REPLIES 2
ballardw
Super User

Do you have a Date variable for each of the records involved? If so then a quick an dirty approach to subset the data could be:

proc sort data=have; by Id class date;run;

data want;

     set have;

     by id class ;

     if last.class;

run;

This would have the latest instance of each id and class combination.

BTW, you would want to set the values to missing not 0.

DBailey
Lapis Lazuli | Level 10

something like this?

proc sort data=have; by id class descending date;run;

data want;

retain QualityPoints num;

retain TotalCredits num;

if first.id then do;

     QualityPoints=0;

     TotalCredits=0;

     end;

if first.class then do;

     if Grade='A' then QualityPoints+4;

     else if Grade='B' then QualityPoints+3;

     else if Grade='C' then QualityPoints+2;

     else if Grade='D' then QualityPoints+1;

   

     TotalCredits+Credits;

     end;

if last.id then GPA=QualityPoints / TotalCredits;

run;

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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
  • 1274 views
  • 0 likes
  • 3 in conversation