Hi SAS Community.
I have a dataset below that keeps track of patient's medications (mtx,ssz, lef, hcq, etn, etc) at each study encounter. The codes for the each med are 0=not currently taking, 1=currently taking, and 2= stopped med, and the medication doses all in mg.
data have;
infile datalines dsd truncover;
input id:$11. enc:32. med_mtx:32. med_mtx_dose:32. med_ssz:32. med_ssz_dose:32. med_lef:32. med_lef_dose:32. med_hcq:32. med_hcq_dose:32. med_etn:32. med_etn_dose:32.;
datalines4;
1016,1,0,,0,,0,,0,,0,
1016,2,,,,,,,,,,
1016,3,,,,,,,,,,
1016,4,,,,,,,,,,
1016,5,,,,,,,,,,
1017,1,0,,0,,0,,1,400,0,
1017,2,0,,0,,0,,1,,0,
1017,3,0,,0,,0,,1,400,0,
1017,4,0,,0,,0,,2,,0,
1017,5,,,,,,,,,,
1018,1,0,,0,,1,20,0,,0,
1018,2,,,,,,,,,,
1018,3,,,,,,,,,,
1018,4,,,,,,,,,,
1018,5,,,,,,,,,,
1023,1,1,20,0,,0,,0,,0,
1023,2,,,,,,,,,,
1023,3,,,,,,,,,,
1023,4,,,,,,,,,,
1023,5,,,,,,,,,,
1024,1,0,,0,,0,,0,,0,
1024,2,,,,,,,,,,
1024,3,,,,,,,,,,
1024,4,,,,,,,,,,
1024,5,,,,,,,,,,
1025,1,0,,0,,1,20,0,,0,
1025,2,,,,,,,,,,
1025,3,,,,,,,,,,
1025,4,0,,1,2000,1,20,0,,0,
1025,5,,,,,,,,,,
1026,1,0,,0,,1,20,1,400,0,
1026,2,,,,,,,,,,
1026,3,0,,0,,1,20,1,400,0,
1026,4,0,,0,,1,20,1,200,0,
1026,5,,,,,,,,,,
1028,1,0,,0,,0,,0,,0,
1028,2,0,,0,,0,,0,,0,
1028,3,0,,0,,0,,0,,0,
1028,4,0,,0,,0,,0,,0,
1028,5,,,,,,,,,,
1029,1,1,25,0,,0,,0,,1,50
1029,2,,,,,,,,,,
1029,3,1,25,1,2000,0,,0,,2,
1029,4,,,,,,,,,,
1029,5,,,,,,,,,,
;;;;
I would like to add a note/text column that summarizes the change in medcations at each encounter by comparing the current meds to the meds at the previous encounters. The note column needs to show the current meds and the doses, med stopped, and new meds added, like this:
Your help is greatly appreciated!
Please review your example data and that "want". In the "want" you show for ID 1017 encounter (assuming the variable Enc is supposed to be encounter) 2 that HCQ is a 400 mg dose. That is not in the data step.
It is a very good idea to explicitly state the names of the variables that hold which information. You say "The codes for the each med are 0=not currently taking, 1=currently taking, and 2= stopped med" but fail to tell us which variable to look in for those values.
You also need to tell us the rules for when "added" is used and if there is any actual significance between using a comma and a | for separating text in the notes.
This gets started:
data want; set have; array c (*) med_mtx med_ssz med_lef med_hcq med_etn ; array d (*) med_mtx_dose med_ssz_dose med_lef_dose med_hcq_dose med_etn_dose ; array n (5) $ 25 _temporary_ ("MTX","SSZ","LEF","HCQ","ETN"); 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;
Please review your example data and that "want". In the "want" you show for ID 1017 encounter (assuming the variable Enc is supposed to be encounter) 2 that HCQ is a 400 mg dose. That is not in the data step.
It is a very good idea to explicitly state the names of the variables that hold which information. You say "The codes for the each med are 0=not currently taking, 1=currently taking, and 2= stopped med" but fail to tell us which variable to look in for those values.
You also need to tell us the rules for when "added" is used and if there is any actual significance between using a comma and a | for separating text in the notes.
This gets started:
data want; set have; array c (*) med_mtx med_ssz med_lef med_hcq med_etn ; array d (*) med_mtx_dose med_ssz_dose med_lef_dose med_hcq_dose med_etn_dose ; array n (5) $ 25 _temporary_ ("MTX","SSZ","LEF","HCQ","ETN"); 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;
Sorry about the discrepancy in the data WANT due to cut and paste. Your solution is exactly what I wanted. Thank you so much for your help and I really appreciate it!
Hi,
I was quick to accept the solution to SAS codes you provided previously and I realized that I need further help with these data.
First, I'd like to respond to your questions you addressed earlier. The code for each of the medication (med_mtx, med_ssz, med_lef,
med_hcq, med_etn) is 0=not currently taking, 1=currently taking, and 2= stopped med. The unit values for the medication dose med_mtx_dose,
med_ssz_dose, and med_hcq_dose are in mg, the value for med_lef_dose is in mg/m^2, and the value for med_etn_dose is mg/kg.
I would like to create a note column to summarize the medication status at each encounter (variable enc) based on these rules:
1) no current med when all meds =0
2) current med has been taken since from the previous encounters (=1)
3) new med "added" but not previously taken (=0 or blank in the previous encounters)
4) stopped med when med =2
An example of ID 1029 shows that med_mtx has been taken since enc=1 and continued till enc 3, new med_ssz added at enc 3 that has not been taken previously, and med_etn stopped at enc 3, so the note column at enc 3 should indicate "Taking MTX 25 mg, Added SSZ 2000 mg, Stopped ETN". Another example of id 1025 enc 4 the note should indicate "Taking SSZ 2000 mg|Taking LEF 20 mg/m^2".
I'm not sure of how to exactly code this since the program will need to look at previous encounters and compare then changes of medication....if that makes any sense.
Any help would be greatly appreciated. Thanks!
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.