Hi I have this
DATA STDTELMT.MERGED_D;
SET STDTELMT.MERGED_C;
IF ANTIBIOTIC ="AMOXICILLIN FOR ABSCESSED TOOTH" THEN ANTIBIOT_NAME = "01";
IF ANTIBIOTIC= "AMOXICILLIN" THEN ANTIBIOT_NAME= "01";
IF ANTIBIOTIC= "CEFTRIAXONE AND AZITHRO FOR GC" THEN ANTIBIOT_NAME="04";
IF ANTIBIOTIC= "CIPRO EYE DROPS" THEN ANTIBIOT_NAME="06";
IF ANTIBIOTIC= "DOXY 200MG 2X DAY X 6 DAYS(OFF STREET)" THEN ANTIBIOT_NAME="09";
IF ANTIBIOTIC= "DOXYCYCLINE 100 MG BID X 10D 1-3-18" THEN ANTIBIOT_NAME="09";
IF ANTIBIOTIC= "AZITHROMYCIN FOR NSU TESTED IN MN" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC= "AZITHROMYCIN FOR NSU" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC= "AZITHROMYCIN AND METRONIDAZOLE FOR BV,TRICH,& CT" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC= "AZITHRO FOR NSU; CT + URINE" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC= "AZITHRO FOR MYCOPLASMA GENITALIUM" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC= "AZITHRO FOR CT" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC = "AZITHRO FOR +CT RECTUM" THEN ANTIBIOT_NAME = "11";
IF ANTIBIOTIC= "AZ/CEFTRIAXONE" THEN ANTIBIOT_NAME="11";
IF ANTIBIOTIC= "LEVOFLOXICIN/VALCYCLOVIR SINCE 1/2" THEN ANTIBIOT_NAME="22";
IF ANTIBIOTIC= "BICILLIN 2.4 MU IM AT ST.FRANCIS ED" THEN ANTIBIOT_NAME="31";
IF ANTIBIOTIC= "MULTIPLE ANTIBIOTICS" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "METRONIDAZOLE GEL FOR BV" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "METRONIDAZOLE FOR BV AT PPWI" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "METRONIDAZOLE FOR BV" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "FLUCONAZOLE FOR YEAST INFECTION" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "CLINDAMYCIN FOR TOOTH ABSCESS" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "CLINDAMYCIN" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "BACTRIM" THEN ANTIBIOT_NAME="77";
IF ANTIBIOTIC= "3 WEEKS AGO" THEN ANTIBIOT_NAME="99";
IF ANTIBIOTIC= "SEE NOTE" THEN ANTIBIOT_NAME="99";
IF ANTIBIOTIC= "9" THEN ANTIBIOT_NAME="99";
IF ANTIBIOTIC= "0" THEN ANTIBIOT_NAME="00";
RUN;
How can i create a new variable antibiot_name using some ting like this; if antibiotic like "am%" or "Az%" then antibiot_name=1
how can i use less code?
The colon indicates that you want to see if the variable begins with the letters am or az
if upcase(antibiotic) =: "AM" or upcase(antibiotic) =: "AZ" then antibiot_name = 1;
The colon indicates that you want to see if the variable begins with the letters am or az
if upcase(antibiotic) =: "AM" or upcase(antibiotic) =: "AZ" then antibiot_name = 1;
Whilst you may get an answer to your question, I would ask why you want to do this. I mean if you want to assign 01 to all records with amoxicillin, what about:
aabbcc amoxicillin def
or
something somwhere is using amoxicillin
or
amoxy was used
or
trimox
Drug coding should be done at using an appropriate dictionary, as you can see particularly in the last example, that simple text finding will not necessarily get you all the records (its a brand name for amoxycillin).
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.