Sum Rows of Specific Variable Based on two Conditions

#1
Please see example dataset below to best illustrate my goal. The cases that need to be changed are in red and blue (arbitrary color choices).

I am cleaning a large dataset and I have about 2,500 duplicates. Basically, one patient (PtID) should never have more than one drug (DrugCode). So, I need to sum the values for DrugMos per the same DrugCode per the same PtID, and I need to sum the values for SzFreeMos per the same DrugCode per the same PtID. In other words, if PtID and DrugCode are the same, then the individual original DrugMos values need to be replaced the sum of those individual DrugMos values (same with SzFreeMos). It would need to look like the "After" example. Once I accomplish the After example, I can easily find duplicate cases and delete those.

Before:
PtID DrugCode DrugMos SzFreeMos
1 ABC 10 1
1 ABC 10 14
1 DEF 0 6
1 HIJ 6 91
2 XYZ 3 151
2 XYZ 74 151
3 XYZ 61 61
3 DEF 7 21

After:
PtID DrugCode DrugMos SzFreeMos
1 ABC 10 15
1 ABC 10 15
1 DEF 0 6
1 HIJ 6 91
2 XYZ 77 151
2 XYZ 77 151
3 XYZ 61 61
3 DEF 7 21


Thank you
 
#2
COMPUTE lagPtID=lag(PtID).

STRING lagDrugCode (A3).
COMPUTE lagDrugCode=lag (DrugCode).

COMPUTE lagDrugMos=lag(DrugMos).
COMPUTE lagSzFreeMos=lag(SzFreeMos).

EXECUTE.

IF lagPtID=PtID and lagDrugCode=DrugCode and lagDrugMos=DrugMos sumSzFreeMos=lagSzFreeMos+SzFreeMos.
IF lagPtID=PtID and lagDrugCode=DrugCode and lagSzFreeMos=SzFreeMos sumDrugMos=lagDrugMos+DrugMos.

EXECUTE.