id rx
1 a
1 b
1 d
2 a
2 b
3 a
3 cI have the following data, I am just trying to find the aggregate total per each patient regardless of rx, I want the following output:
id total
1 3
2 2
3 2
If you have no duplicate rx then use PROC FREQ.
If you do have duplicate rx, use either double PROC FREQ or PROC SQL.
proc SQL;
create table want as
select id, count(distinct rx) as num_rx
from have;
quit;
If you have no duplicate rx then use PROC FREQ.
If you do have duplicate rx, use either double PROC FREQ or PROC SQL.
proc SQL;
create table want as
select id, count(distinct rx) as num_rx
from have;
quit;
Thank you! just to add you need a by rx statement after
@lillymaginta sorry, yes, should be GROUP BY ID in that SQL query.
The proc freq is relatively straightforward.
proc freq data=have noprint;
table id*rx/out=id_rx_count;
run;
proc freq data=id_rx_count noprint;
table id / out=by_id;
run;
proc print data=by_id;
run;
Could you give an example of a the double freq you mentioned or point me some where that does?
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 save with the early bird rate—just $795!
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.