Help using Base SAS procedures

Setting Duplicate Values to 0

Reply
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.

Thanks!

Super User
Posts: 10,500

Re: Setting Duplicate Values to 0

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.

Super Contributor
Posts: 578

Re: Setting Duplicate Values to 0

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;

Ask a Question
Discussion stats
  • 2 replies
  • 181 views
  • 0 likes
  • 3 in conversation