@ballardw : Thank you for responding; X is a class of drugs. So Patient 2 indeed got 2 different drugs belonging to class X on 2 different dates. Each patient has been sorted according to drug encounter date - meaning patient gets some drug belonging to X on date 1, gets drug class Y on date 2, and drug class Z on date 3. Patient 2 has drug class X (two different drugs) given on 2 different dates. In some rare instances, 2 different drugs belonging to drug class X may be given on same date. I need to calculate the number and % of drug class Y, Z etc who were given drug class X. I also have a column which gives the first encounter date of drug class X. Input Data Set Patient_id Encounter Date First Encounter of Drug Class X Drug Class 1 Date 1 Date 1 X 1 Date 2 Date 1 Y 1 Date 3 Date 1 Z 2 Date 4 Date 4 X 2 Date 5 Date 4 O 2 Date 6 Date 4 X
... View more