DATA Step, Macro, Functions and more

finding frequency of a specific drug one per id

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 110
Accepted Solution

finding frequency of a specific drug one per id

id  drug     v_date 
1   11         01/02/2004
1    11        03/03/2005
1    11        8/3/2005        
1    22        5/4/2005
1   22         6/6/2005

Hi All,

I have something similar with the above database. Multiple drugs per id and the same drug can have more than one v_date. My question I want to find the number of patients who obtained at least one drug (for example at least 1 of drug number 11) . So if I have 10 patient who had at least one of drug (no 11) in different v_date, I want to obtain an output that state: drug 11 frequency= 10, and so on 


Accepted Solutions
Solution
‎03-14-2016 09:00 AM
Trusted Advisor
Posts: 1,115

Re: finding frequency of a specific drug one per id

Hi @lillymaginta,

 

Try this:

proc sql;
create table want as
select drug, count(distinct id) as frequency
from have
group by drug;
quit;

View solution in original post


All Replies
Solution
‎03-14-2016 09:00 AM
Trusted Advisor
Posts: 1,115

Re: finding frequency of a specific drug one per id

Hi @lillymaginta,

 

Try this:

proc sql;
create table want as
select drug, count(distinct id) as frequency
from have
group by drug;
quit;
Frequent Contributor
Posts: 110

Re: finding frequency of a specific drug one per id

Thank you FreelanceReinhard
☑ This topic is SOLVED.

Need further help from the community? Please ask a new question.

Discussion stats
  • 2 replies
  • 216 views
  • 3 likes
  • 2 in conversation