BookmarkSubscribeRSS Feed
deleted_user
Not applicable
Hi
I need to generate output that looks like this (number of patients and number of events per each event)

# patients # events
Bleeding 10 14
Stroke 8 12
etc

How can proc tabulate help me do this? So far i only know how to get the #events per event type.

Message was edited by: sareenk Message was edited by: sareenk
6 REPLIES 6
Peter_C
Rhodochrosite | Level 12
what is the structure of the data set you start with?
deleted_user
Not applicable
the structure of my dataset is that it is in long format, meaning i have multiple rows per patient with the corresponding event type.
Cynthia_sas
SAS Super FREQ
A mini-sample would help. If your data looked like this:
[pre]
Patient Event Date
alan bleeding 12/10/08
alan stroke 12/12/08
alan bleeding 12/14/08
bob stroke 12/15/08
bob stroke 12/18/08
carl bleeding 12/16/08
carl stroke 12/17/08
dan bleeding 12/19/08
[/pre]

What would you expect to see?

[pre]
One possibility:
Event NumPT NumEv
Bleeding 4 4 (alan counted twice)
Stroke 4 4 (bob counted twice)

Another Possibility:
Event NumUniquePT NumEv
Bleeding 3 4 (alan counted once)
Stroke 3 4 (bob counted once)
[/pre]

Or perhaps you have other report requirements???

cynthia
deleted_user
Not applicable
Yes, it would need to look like the second possibility, like this:

Bleeding: #patients: 3 # bleeding events: 4
Stroke #patients: 3 # stroke events: 4

Since 4 strokes are hapening in 3 patients, and so on.
Does proc tabulate do this for me?
Currently, the way I do this is i say

data pts;
if first.patcode;
by patcode;
where event='Bleeding';
run;
etc for each event I have.
I am looking for a more concise method

Thank you
Cynthia_sas
SAS Super FREQ
Hi:
With a little data "preparation", you can create the report you want with PROC TABULATE. Essentially, you need to make a numeric variable whose value will be 1 or 0 depending on whether you want to count the patient or not -- for a particular patient/event combination.

This program assumes that the events are all going to be spelled exactly the same. In other words, stroke will ALWAYS be "stroke" and not "stroke" for one obs and "strke" for another obs and "strokes" for another obs.

The new variable, COUNTTHIS, will be used as an analysis variable by PROC TABULATE. EVENT will be placed in the row dimension of the table and COUNTTHIS and N will be in the column dimension of the table.

This program assumes that the data already exists in the PT_EVENT data set.

cynthia
[pre]
proc sort data=pt_event;
by patient event;
run;

ods listing;
data uniq_pte;
set pt_event;
by patient event;
if first.event then countthis = 1;
else countthis = 0;
run;

** Print just to show result of using FIRST.EVENT;
proc print data=uniq_pte;
title 'Create Variable to Count Unique Patients for Each Event';
title2 '(Only the first event for every unique patient/event combo';
title3 'will get a 1 in order to be counted.)';
format date mmddyy10.;
run;

proc tabulate data=uniq_pte f=comma8.;
title 'Use Proc Tabulate';
class event;
var countthis;
table event all='Total',
countthis="Number Unique Patients" n="Number Events";
keylabel sum = ' ';
run;
[/pre]
deleted_user
Not applicable
Thank you so much for your help, it worked! If I knew this forum was so helpful I would have asked about this a few years ago!
A million thanks!

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
  • 6 replies
  • 834 views
  • 0 likes
  • 3 in conversation