BookmarkSubscribeRSS Feed
tbn1
Calcite | Level 5

I am using a large database of patients. Each has a hospital assigned (there are several hundred hospitals and 100,000+ patients). I created a frequency table to determine how many times each hospital performed the procedure during the years of the study (each patient only has 1 procedure and it is during a given year).

 

I would like to create a new variable where for a given patient row, they have a count of number of procedures performed at their treatment hospital that year (basically taking that data from the frequency table for their specific hospital). 

 

I appreciate any assistance!

 

 

 

5 REPLIES 5
Reeza
Super User

Without further details, I can illustrate how to pipe your results from PROC FREQ into a data set, but if you need more specific help you'll need to provide significantly more details and sample data. 

 

proc freq data=sashelp.class noprint;

table age * sex / out = want;

run;


proc print data = want label noobs;
run;

@tbn1 wrote:

I am using a large database of patients. Each has a hospital assigned (there are several hundred hospitals and 100,000+ patients). I created a frequency table to determine how many times each hospital performed the procedure during the years of the study (each patient only has 1 procedure and it is during a given year).

 

I would like to create a new variable where for a given patient row, they have a count of number of procedures performed at their treatment hospital that year (basically taking that data from the frequency table for their specific hospital). 

 

I appreciate any assistance!

 

 

 


 

Astounding
PROC Star

It's not 100% clear what you are seeking, but this might be it:

 

proc freq data=have;

tables hospital / noprint out=counts (keep=hospital count);

run;

 

proc sort data=have;

by hospital;

run;

 

data want;

merge have counts;

by hospital;

run;

tbn1
Calcite | Level 5
This is exactly what I want! But I would like to stratify it by one more layer - counts of hospital by year. Can you help me do that?
Thanks so much!!
tbn1
Calcite | Level 5

Actually - so I was able to get counts of hospital*year. However, when I try to merge that back into the main sheet, I lose a lot of my overall sample.

 

I want to import it back into the sheet such that for patient #3 who had surgery at hospital A in 2014, the count is 5 and that the count is 5 for the other 4 patients that had surgery at hospital A in 2014.

Astounding
PROC Star

Post the log from the program you ran.  It's likely very easy to fix.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

Register now!

Mastering the WHERE Clause in PROC SQL

SAS' Charu Shankar shares her PROC SQL expertise by showing you how to master the WHERE clause using real winter weather data.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 872 views
  • 2 likes
  • 3 in conversation