BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
lewis
Calcite | Level 5

Hi all,

I have a question that has been bugging me for a while now.  Problem:  I am given unique patient id's (accessionnumber) and blood sample test dates with patients receiving multiple blood samples.  The question is how to count the number of samples each patient receives (No. of Samples) and how many patients are in each sample size (No. of patients).  I have no problem finding the No. of samples, but how do i count how many people are in each sample size ie. how many people have one sample, how many people have two etc.  I have included code for what i have done.  Thanks!

proc sql; select distinct count(*) as  nofpats from (

select distinct  accessionnumber from

a.labresults_ontherapy) ; quit;

1 ACCEPTED SOLUTION

Accepted Solutions
Tom
Super User Tom
Super User

proc sql;

  select

      nofsamp "No. of Samples"

     ,count(*) as  nofpats "No. of Patients"

  from

    (select

        accessionnumber

      , count(*) as nofsamp

     from a.labresults_ontherapy

     group by 1

    )

   group by 1

  ;

quit;

View solution in original post

5 REPLIES 5
Linlin
Lapis Lazuli | Level 10

data have;

input id dates;

cards;

1 01/15/2013

1 01/15/2013

2 01/15/2013

2 01/15/2013

2 01/15/2013

2 01/15/2013

3 01/15/2013

4 01/15/2013

;

proc sql;

create table want

    as select size,count(*) as number

       from(select id,count(*) as size from have

    group by id,dates) group by size;

quit;

  proc print;run;

PGStats
Opal | Level 21

proc sql;

select nbSamples, count(*)  as nbPatients

from (

     select  accessionnumber, count(*) as nbSamples

     from a.labresults_ontherapy

     group by accessionnumber)

group by nbSamples;

quit;

PG

PG
lewis
Calcite | Level 5

Thanks for all the help guys.  I need the final output to be slightly different though.

No. of Samples        No. of Patients (ie  # ofpatients with that number of blood draws)

1                                   3

2                                   6

3                                   1

4                                   7

5                                   13

6                                   1

 

The code I added previously gives the left column.  The right count column for each # of samples is the problem.

Tom
Super User Tom
Super User

proc sql;

  select

      nofsamp "No. of Samples"

     ,count(*) as  nofpats "No. of Patients"

  from

    (select

        accessionnumber

      , count(*) as nofsamp

     from a.labresults_ontherapy

     group by 1

    )

   group by 1

  ;

quit;

lewis
Calcite | Level 5

Awesome thanks Tom!  I was really having problems with relating the two columns.  I believe PGStats reply to pretty close as well.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

What is Bayesian Analysis?

Learn the difference between classical and Bayesian statistical approaches and see a few PROC examples to perform Bayesian analysis in this video.

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
  • 5 replies
  • 10547 views
  • 3 likes
  • 4 in conversation