Hi all. I am looking at hospitalization data and have columns for the county FIPS code that the hospital is in and the number of hospitalizations for a given month and year. I have multiple rows (hospitals) that exist in the same county. I want to sum the total number of hospitalizations per county.
This is what I have: This is what I want:
county_fips | month | year | hospitalizations county_fips | month | year | hospitalizations_sum
01001 1 2020 5 01001 1 2020 15
01001 1 2020 10 01001 2 2020 6
01001 2 2020 6 01002 1 2020 10
01002 1 2020 6
01002 1 2020 4
I am at a loss for how to make this happen. Any help is appreciated!
PROC SUMMARY is the perfect tool for this
proc summary data=have nway;
class county_fips month year;
var hospitalizations;
output out=want sum=hospitalizations_sum;
run;
PROC SUMMARY is the perfect tool for this
proc summary data=have nway;
class county_fips month year;
var hospitalizations;
output out=want sum=hospitalizations_sum;
run;
This is awesome. Thank you so much. My boss and I thank you. xD
It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.
Learn how use the CAT functions in SAS to join values from multiple variables into a single value.
Find more tutorials on the SAS Users YouTube channel.
Ready to level-up your skills? Choose your own adventure.