Hi All,
I am trying to count (frequency/%) for different/concomitant drug classes by patients who are taking a particular class X. I Need to frequency count only class A,B etc. X class should be 1st used for each patient based on DATE
Patient ID Date Drug Class
1 DateFormat9. X
1 DateFormat9. A
1 DateFormat9. B
2 DateFormat9. X
2 DateFormat9. A
2 DateFormat9. B
2 DateFormat9. X
Thanks
Your example shows Patient 2 with 2 "X" values.
You didn't supply anything resembling an actual date so I can't tell if that is an error or if you have two identical dates for patient 2.
Better would be to provide some actual data, a small enough set you can calculate by hand the desired results, for those variables and then show the expected result.
Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the {i} icon or attached as text to show exactly what you have and that we can test code against.
@ballardw : Thank you for responding;
X is a class of drugs. So Patient 2 indeed got 2 different drugs belonging to class X on 2 different dates. Each patient has been sorted according to drug encounter date - meaning patient gets some drug belonging to X on date 1, gets drug class Y on date 2, and drug class Z on date 3. Patient 2 has drug class X (two different drugs) given on 2 different dates. In some rare instances, 2 different drugs belonging to drug class X may be given on same date.
I need to calculate the number and % of drug class Y, Z etc who were given drug class X. I also have a column which gives the first encounter date of drug class X.
Input Data Set
| Patient_id | Encounter Date | First Encounter of Drug Class X | Drug Class |
| 1 | Date 1 | Date 1 | X |
| 1 | Date 2 | Date 1 | Y |
| 1 | Date 3 | Date 1 | Z |
| 2 | Date 4 | Date 4 | X |
| 2 | Date 5 | Date 4 | O |
| 2 | Date 6 | Date 4 | X |
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.