Hello SAS experts: Can you give me a suggestion on how I can do the following chronologically (based on the Rx_date)? The sample data is provided below. Thanks a lot in advance! Step1: Count the number of switches among the drugs for each patient ; for examples, Pat_ID 201, should have switch count =8;Pat_ID 202 would have switch count=6 , and Pat_ID 203 would have switch count=0; Step2: For patients never switched, flag them as the drug they were on; For example, Pat_ID 203, would have a Uflag='Stable' & DrugStable='DrugB'; Pat_ID 201 & 202 would have Uflag='Switcher' & DrugSwitch='DrugC, DrugA,DrugC, DrugA, DrugDrugC, DrugB, DrugC'; Step 3. Output the last RX_Date record for each patient with the flags in Step 1 & 2 and retain the first Rx_Date for all patients; while creating switch date fields to keep the switch dates for each switcher such as switch1, switch2, switch3,....; Step 4: Count the number of 'Stable' patients for each drug; data have; input PAT_ID RX_DT : ddmmyy10. RX_Name $; format RX_DT ddmmyy10.; datalines;; 201 18/07/2013 DrugA 201 27/12/2013 DrugA 201 13/06/2013 DrugC 201 19/08/2013 DrugC 201 01/05/2014 DrugC 201 14/10/2013 DrugC 201 20/02/2014 DrugC 201 27/03/2014 DrugA 201 16/09/2013 DrugB 201 18/12/2013 DrugC 202 16/04/2014 DrugC 202 16/01/2014 DrugC 202 02/10/2013 DrugC 202 15/07/2013 DrugC 202 13/05/2013 DrugC 202 11/03/2014 DrugC 202 11/11/2013 DrugB 202 23/09/2013 DrugA 202 05/08/2013 DrugA 202 24/06/2013 DrugA 203 11/12/2014 DrugB 203 11/09/2015 DrugB 203 23/09/2016 DrugB 203 05/08/2017 DrugB 203 24/06/2013 DrugB ; run; proc sort data=have; by pat_id rx_dt; quit;
... View more