I have a dataset which shows the number of packs of a drug administered to different patients over a series of months. Here is an example of the structure of the dataset: data have;
input ID _201510 _201511 _201512 _201601 _201602 _201603;
cards;
3 1 1 . 2 1 1
8 1 . 1 1 2 2
17 . . 1 . . 1
;
run; A patient receives a 30% discount on the first 4 packs, no discount on the 5th and 6th pack, and a 50% discount on any packs 7 and above. Packs Discount Interval 1 – 4 30% 1 5 – 6 0 2 7 and above 50% 3 New data arrives every month, and at the end of each quarter, I do a follow-up to calculate the number of packs per interval that have been administered to a patient during the last three months. Specifically, I need help writing a program that achieves the following: data want;
input ID _201510 _201511 _201512 _201601 _201602 _201603 PackInt1 PackInt2 PackInt3;
cards;
3 1 1 . 2 1 1 2 2 0
8 1 . 1 1 2 2 2 2 1
17 . . 1 . . 1 1 0 0
;
run; Notice that, for patient ID 3, the value of PackInt1 is 2 rather than 4. The reason is that the first two packs have already been dealt with in the previous follow-up (2015Q3). Similarly, patient ID 17 has a value of 1 for PackInt1, because the first pack they received was also dealt with in the previous follow-up. Any ideas on how I can achieve the above? I need a code that is flexible enough to handle the addition of a new column every month.
... View more