BookmarkSubscribeRSS Feed
hanahch
Calcite | Level 5

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!

2 REPLIES 2
ballardw
Super User

Until you provide something that has the "correct units" in the data you are asking for something that is impossible to code.

 

There is no way we can tell what unit is involved with what you have posted

hanahch
Calcite | Level 5

 

I revised the dataset by adding correct unit in each dose field.  I hope this helps and it should take care of the correct unit to dose issue.  What I need help with is how to determine a new med added if it hasn't been taking in the previous encounters.  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". 


data have;
infile datalines dsd truncover;
input id:$11. enc:32. mtx:32. mtx_dose:$15. ssz:32. ssz_dose:$15. lef:32. lef_dose:$15. rtx:32. rtx_dose:$15. toc:32. toc_dose:$15.;
datalines4;
102,1,0,,0,,0,,1,400 mg/m^,0,
102,2,0,,0,,0,,1,,0,
102,3,0,,0,,0,,1,400 mg/m^,0,
102,4,0,,0,,0,,2,,0,
102,5,,,,,,,,,,
106,1,0,,0,,1,20 mg,0,,0,
106,2,,,,,,,,,,
106,3,,,,,,,,,,
106,4,0,,1,2000 mg,1,20 mg,0,,0,
106,5,,,,,,,,,,
107,1,0,,0,,1,20 mg,1,400 mg/m^,0,
107,2,,,,,,,,,,
107,3,0,,0,,1,20 mg,1,400 mg/m^,0,
107,4,0,,0,,1,20 mg,1,200 mg/m^,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 mg,0,,0,,0,,1,50 mg/kg
109,2,,,,,,,,,,
109,3,1,25 mg,1,2000 mg,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]));
if c[i]=2 then notes=catx(',',notes,catx(' ',"Stopped",n[i]));
end;
run;

 

Thanks!

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 2 replies
  • 461 views
  • 0 likes
  • 2 in conversation