BookmarkSubscribeRSS Feed
Deep_Impact
Calcite | Level 5

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

2 REPLIES 2
ballardw
Super User

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.

Deep_Impact
Calcite | Level 5

@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_idEncounter Date First Encounter of Drug Class XDrug Class
1Date 1Date 1X
1Date 2 Date 1Y
1Date 3 Date 1Z
2Date 4Date 4X
2Date 5Date 4O
2Date 6Date 4X

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 519 views
  • 0 likes
  • 2 in conversation