Help using Base SAS procedures

Setting Duplicate Values to 0

Occasional Contributor
Posts: 9

Setting Duplicate Values to 0

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.


Super User
Posts: 13,498

Re: Setting Duplicate Values to 0

Posted in reply to jwestra84

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;


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

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

Super Contributor
Posts: 578

Re: Setting Duplicate Values to 0

Posted in reply to jwestra84

something like this?

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

data want;

retain QualityPoints num;

retain TotalCredits num;

if then do;




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;




if then GPA=QualityPoints / TotalCredits;


Ask a Question
Discussion stats
  • 2 replies
  • 3 in conversation