I have a data like this
| ANTIBIOTIC | |
| ANTIBIOTIC | Frequency |
| AZITHROMYCIN | 1 |
| CEFTRIAXONE/AZITHROMYCIN | 3 |
| DOXYCYCLINE | 3 |
| FLUCONAZOLE | 1 |
| METRONIDAZOLE | 1 |
| UNKNOWN | 1 |
I wanted to have a table like this
| ANTIBIOT_NAME | Frequency |
| 4 | 3 |
| 9 | 3 |
| 11 | 4 |
| 77 | 3 |
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_NAME | Frequency |
| 4 | 3 |
| 9 | 3 |
| 11 | 1 |
| 77 | 3 |
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?
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;
April 27 – 30 | Gaylord Texan | Grapevine, Texas
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!
Still thinking about your presentation idea? The submission deadline has been extended to Friday, Nov. 14, at 11:59 p.m. ET.
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.
Ready to level-up your skills? Choose your own adventure.