BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lillymaginta
Lapis Lazuli | Level 10
id rx
1  a
1  b
1  d
2  a 
2  b
3  a
3 c

I 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

1 ACCEPTED SOLUTION

Accepted Solutions
Reeza
Super User

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;

View solution in original post

4 REPLIES 4
Reeza
Super User

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;

lillymaginta
Lapis Lazuli | Level 10

Thank you! just to add you need a by rx statement after 

Reeza
Super User

@lillymaginta sorry, yes, should be GROUP BY ID in that SQL query.

 

@rbikes

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;

 

 

rbikes
Obsidian | Level 7

Could you give an example of a the double freq you mentioned or point me some where that does?

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
  • 4 replies
  • 2111 views
  • 1 like
  • 3 in conversation