BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dhana18
Obsidian | Level 7

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?

1 ACCEPTED SOLUTION

Accepted Solutions
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller

View solution in original post

2 REPLIES 2
PaigeMiller
Diamond | Level 26

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;
--
Paige Miller
RW9
Diamond | Level 26 RW9
Diamond | Level 26

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).

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

Register now!

How to Concatenate Values

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 2 replies
  • 4503 views
  • 1 like
  • 3 in conversation