Study ID | Drug1 | Drug2 | Drug3 |
00001 | 1 | 0 | 0 |
00001 | 0 | 0 | 1 |
Hello,
I just started using SAS again and I have yet to refresh my memory.
I'm currently investigating 3 drugs - patients are only supposed to be prescribed to only 1 drug.
However, some patients received more than 1 drug (as depicted in the table above) and I want to delete these specific individuals from the data.
Any codes to identify and delete these individuals? Any advice/help would be appreciated.
Hi novinosrin,
Study_ID in this case would be the patient_id.
Maybe this:
data have;
format studyid z5.;
input studyid drug1-drug3;
datalines;
00001 1 0 0
00001 0 0 1
00002 0 1 0
;
run;
data want;
set have;
by studyid;
if first.studyid then
rx_total=0;
rx_total+sum(of drug:);
if last.studyid and rx_total=1 then
output;
drop rx_total;
run;
assumes only one drug can be 1 for any given observation.
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!
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.