id drug
1 a
1 a
1 a
1 b
1 c
1 c
2 a
2 b
2 b
2 b
2 c
2 cI have the following data. I want to create an output that provide me with the total number of id who have 2 or more of a specific drug. For example for id1: count the id one for a, none for b, and one for c
here is the output I am looking for
drug total ids
a 1
b 1
c 2
Post test data in the form of a datastep!
Just a rough guess:
proc sql;
create table WANT as
select ID,
DRUG
count(*) as RES
from HAVE
group by ID,DRUG
having RES >= 2;
quit;
If you know how to read PROC FREQ output, two PROC FREQs should do the job nicely.
proc freq data=have;
tables drug * id / noprint out=counts;
run;
proc freq data=counts;
tables drug;
where count > 1;
run;
The output data set from the first PROC FREQ counts the number of observations for each DRUG / ID combination.
The report from the second PROC FREQ will give you a list of the drugs, and the FREQUENCY column is the number of IDs.
Thank you all!
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.