I'd like to do the following, but I don't know how to code it:
I have 5 character variables (med_1, med_2 ... med_5) and I want to create a new variable, "antibiotic", which will = 1 if ANY of med_1-med_5 contain the name of an antibiotic.
I'd like to create a list of possible antibiotic names: ampicillin, amoxicillin, gentamycin, etc. and then tell SAS to check the contents of med_1-med_5 and if ANY are equal to a drug name in my list, then make antibiotic=1, otherwise, antibiotic=0.
Thanks in advance for your help!
There are a number of ways to do what you want. One way would be:
data have;
informat med1-med5 $20.;
input med1-med5;
cards;
this that something another placebo
this that amoxicillin another placebo
this that something another placebo
this that something another gentamycin
ampicillin amoxicillin gentamycin somethingelse that
;
data want (drop=i);
set have;
array meds(*) $20. med1-med5;
antibiotic=0;
do i=1 to dim(meds);
if meds(i) in ("ampicillin", "amoxicillin", "gentamycin")
then antibiotic=1;
end;
run;
Thank you so much! Is there a way to check for anything beginning with "amox"? (so it would capture "amoxil", "amoxicillin", etc.?)
There is probably a more efficient way of coding it, but the following should work:
data have;
informat med1-med5 $20.;
input med1-med5;
cards;
this that something another placebo
this that amoxicillinplus another placebo
this that something another placebo
this that something another gentamycin
ampicillin amoxicillinextra gentamycinplus1 somethingelse that
;
data want;
set have;
array meds(*) $20. med1-med5;
array drugs(3) $20. ("ampici", "amoxici", "gentamyci");
antibiotic=0;
do i=1 to dim(meds);
do j=1 to dim(drugs);
if strip(drugs(j)) =: meds(i) then antibiotic=1;
end;
end;
run;
Hi .Art .
You can use colon operator like:
if meds(i) in: ("amp", "amox", "gent")
Ksharp
Fantastic! Thank you both.
Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.
Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.
Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.
Find more tutorials on the SAS Users YouTube channel.