Hi SAS community,
I have a dataset that keeps track of medication (mtx,ssz, lef, rtx, toc, etc) taken at each encounter (enc).
The code for each medication is 0=not currently taking, 1=currently taking, and 2= stopped med.
The unit for mtx_dose, ssz_dose, and lef_dose is in mg, rtx_dose in mg/m^ and toc_dose in mg/kg.
I would like to add a note column that summarizes the change in medcations at each encounter by comparing the current meds to the meds in the previous encounters. The program below works fine except that when a new med is added, I want to check if it hasn't been taken previously. The note should show the current meds and new meds with their correct corresponding dose units, and stopped meds.
An example of ID 109 shows med mtx taken since enc=1 and continued till enc 3, new med ssz added at enc 3 that has not been taken previously,
and med_toc stopped at enc 3, so the note at enc 3 should indicate "Taking MTX 25 mg, added SSZ 2000 mg, stopped TOC".
Another example of id 106 enc 4, the unit is incorrect for LEF and it should indicate "Taking SSZ 2000 mg,Taking LEF 20 mg/m^2".
data have;
infile datalines dsd truncover;
input id:$11. enc:32. mtx:32. mtx_dose:32. ssz:32. ssz_dose:32. lef:32. lef_dose:32. rtx:32. rtx_dose:32. toc:32. toc_dose:32.;
datalines4;
102,1,0,,0,,0,,1,400,0,
102,2,0,,0,,0,,1,,0,
102,3,0,,0,,0,,1,400,0,
102,4,0,,0,,0,,2,,0,
102,5,,,,,,,,,,
106,1,0,,0,,1,20,0,,0,
106,2,,,,,,,,,,
106,3,,,,,,,,,,
106,4,0,,1,2000,1,20,0,,0,
106,5,,,,,,,,,,
107,1,0,,0,,1,20,1,400,0,
107,2,,,,,,,,,,
107,3,0,,0,,1,20,1,400,0,
107,4,0,,0,,1,20,1,200,0,
107,5,,,,,,,,,,
108,1,0,,0,,0,,0,,0,
108,2,0,,0,,0,,0,,0,
108,3,0,,0,,0,,0,,0,
108,4,0,,0,,0,,0,,0,
108,5,,,,,,,,,,
109,1,1,25,0,,0,,0,,1,50
109,2,,,,,,,,,,
109,3,1,25,1,2000,0,,0,,2,
109,4,,,,,,,,,,
109,5,,,,,,,,,,
;;;;
run;
data want;
set have;
array c (*) mtx ssz lef rtx toc ;
array d (*) mtx_dose ssz_dose lef_dose rtx_dose toc_dose ;
array n (5) $ 25 _temporary_ ("MTX","SSZ","LEF","RTX","TOC");
length notes $ 200;
if max(of c(*)) = 0 then notes="No current meds";
Else do i=1 to dim(c);
if c[i]=1 then notes=catx(',',notes,catx(' ',"Taking",n[i],d[i],'mg'));
if c[i]=2 then notes=catx(',',notes,catx(' ',"Stopped",n[i]));
end;
run;
Any help would be greatly appreciated. Thanks!