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!
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!
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;
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.
Post the log from the program you ran. It's likely very easy to fix.
April 27 – 30 | Gaylord Texan | Grapevine, Texas
Walk in ready to learn. Walk out ready to deliver. This is the data and AI conference you can't afford to miss.
Register now and lock in 2025 pricing—just $495!
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.