BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

I have a data like this 

ANTIBIOTIC
ANTIBIOTICFrequency
AZITHROMYCIN1
CEFTRIAXONE/AZITHROMYCIN3
DOXYCYCLINE3
FLUCONAZOLE1
METRONIDAZOLE1
UNKNOWN1

 I wanted to have a table like this

ANTIBIOT_NAMEFrequency
43
93
114
773

 i used this code

DATA AprilNin.MERGE_April2019_E;
SET AprilNin.MERGE_April2019_D;
IF ANTIBIOTIC =: "AZI" then ANTIBIOT_NAME = "11";
ELSE IF ANTIBIOTIC =: "CEF" then ANTIBIOT_NAME = "04";
ELSE IF ANTIBIOTIC =: "DOX" then ANTIBIOT_NAME = "09";
ELSE IF ANTIBIOTIC = "" then ANTIBIOT_NAME = "00";
ELSE ANTIBIOT_NAME="77";
RUN;

and result is this NOT what I want

ANTIBIOT_NAMEFrequency
43
93
111
773

the count of AZI (11) should be 4 but it is showing 1.

How do i code to this  CEFTRIAXONE/AZITHROMYCIN to count for both Azithromycin and Ceftriaxone?

1 REPLY 1
Jagadishkatam
Amethyst | Level 16

Hi  Dhana,

 

I responded to the same yesterday, hope you tried

could you please let me know if the below code will help

 

data have;
input ANTIBIOTIC &:$100.;
cards;
AZITHROMYCIN	
CEFTRIAXONE/AZITHROMYCIN	
DOXYCYCLINE	
FLUCONAZOLE	
METRONIDAZOLE	
UNKNOWN	
;

data want(rename=(newvar=ANTIBIOTIC));
set have;
do i = 1 to countw(ANTIBIOTIC,'/');
newvar=scan(ANTIBIOTIC,i,'/');
output;
end;
drop ANTIBIOTIC;
run;

data want2;
set want;
IF ANTIBIOTIC = "CEFTRIAXONE" then ANTIBIOT_NAME = "04";
ELSE IF UPCASE(ANTIBIOTIC) =: "AZ" OR UPCASE(ANTIBIOTIC) =: "ZI" then ANTIBIOT_NAME = "11";
ELSE IF UPCASE(ANTIBIOTIC) =: "CEFTRIAXONE/AZITHROMYCIN" then ANTIBIOT_NAME = "11";
ELSE IF UPCASE(ANTIBIOTIC) =: "DO" then ANTIBIOT_NAME = "09";
ELSE IF ANTIBIOTIC = "0" THEN ANTIBIOT_NAME = "00";
ELSE IF ANTIBIOTIC="" THEN ANTIBIOT_NAME="00";
ELSE ANTIBIOT_NAME="77";
run;

PROC FREQ DATA=want2;
TABLE ANTIBIOT_NAME/NOROW NOCOL NOPERCENT;
RUN;
Thanks,
Jag

sas-innovate-2026-white.png



April 27 – 30 | Gaylord Texan | Grapevine, Texas

Registration is open

Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 1 reply
  • 673 views
  • 0 likes
  • 2 in conversation