Help using Base SAS procedures

how to count something using proc sql

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 14
Accepted Solution

how to count something using proc sql

I have a dataset (patients) as such:

Pat_ID     Hos     Date

A              11        1/1/2012

B              12         2/3/2012

B              13         2/3/2012

C              11         4/1/2012

C               11         4/5/2012

How do I count using proc sql such that the outcome looks something like this:

Pat_ID      Visits

A                 1

B                   1

C                    2

Since B has two visits on the same date, they are considered as only 1 visit, whereas C has 2 visits because they are on different dates.


Accepted Solutions
Solution
‎04-02-2015 02:20 PM
Contributor
Posts: 52

Re: how to count something using proc sql

you can try:

proc sql;

select pat_id, count(distinct date) as visits

from   patients

group by pat_id;

quit;

View solution in original post


All Replies
Solution
‎04-02-2015 02:20 PM
Contributor
Posts: 52

Re: how to count something using proc sql

you can try:

proc sql;

select pat_id, count(distinct date) as visits

from   patients

group by pat_id;

quit;

🔒 This topic is solved and locked.

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

Discussion stats
  • 1 reply
  • 185 views
  • 0 likes
  • 2 in conversation