BookmarkSubscribeRSS Feed
Dhana18
Obsidian | Level 7

Good morning,

i have a data like this 

ANTIBIOTIC
ANTIBIOTICFrequency
AZITHROMYCIN1
CEFTRIAXONE/AZITHROMYCIN3
DOXYCYCLINE3
FLUCONAZOLE1
METRONIDAZOLE1
UNKNOWN1

I coded like this:

DATA AprilNin.MERGE_April2019_E;
SET AprilNin.MERGE_April2019_D;
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;
/*CHECKING TO SEE IF THE CODE ABOVE WORKED*/
PROC FREQ DATA=AprilNin.MERGE_April2019_E;
TABLE ANTIBIOT_NAME/NOROW NOCOL NOPERCENT;
RUN;

 and the result shows:

ANTIBIOT_NAMEFrequency
93
114
773

  Why am i not getting Ceftriaxone (04) in the result table? 

3 REPLIES 3
Jagadishkatam
Amethyst | Level 16

The CEFTRIAXONE is getting counted under the ANTIBIOT_NAME = "11" due to the if condition UPCASE(ANTIBIOTIC) =: "CEFTRIAXONE/AZITHROMYCIN" . Inorder to get the ANTIBIOT_NAME = "04", you need to have the ANTIBIOTIC = "CEFTRIAXONE" only. But seems like the data does not have it. Please check.

 

 

Thanks,
Jag
Dhana18
Obsidian | Level 7
Yes, the dat does not have ceftriaxone separately. Is there a way to code to get both Ceftriaxone and Azithromycin info? Or I should separate then before I import to SAS?
Jagadishkatam
Amethyst | Level 16

Could you please try the below code if it is the one you are expecting

 

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

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

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
  • 3 replies
  • 846 views
  • 0 likes
  • 2 in conversation