Hello,
I am currently working with a large surgical healthcare dataset with many individual observations (patients) that are clustered within hospitals. Right now, one observation corresponds to an individual patient, (i.e. a surgical admission), and I have variables identifying hospital ID, gender, year of surgery, etc. My goal is to create a new dataset where each observation represents an individual hospital. I would like the variables in that dataset to reflect hospital proportions (means) of dichotomous variables for that year (e.g. proportion female patients per hospital per year). I tried using the following code to calculate means of all variables at once for each year, hoping to do this across 6 years and then merge all the datasets together. However, the output dataset only includes the mean for variable 1, not all 6 variables.
proc means data=have mean nway;
class hospid;
var var1 var2 var3 var4 var5 var6;
output out=test mean=prop;
where year=2011;
run;
I cannot figure out how to create an output dataset that lists the mean (proportion) for all variables, classified by hospital ID. Does anyone have any suggestions?
Thank you!
proc summary data=have nway;
class hospid year;
var var1 var2 var3 var4 var5 var6;
output out=test mean=prop1-prop6;
run;
No need to create data sets by year and then combine them — that's just extra and unnecessary work. The code above gives you one data set with all of your results.
This looks like it should be perfect. Thank you!
I do intend to perform additional models on this new dataset. Is there any reason that would necessitate that I use proc report or proc tabulate?
Thank you all!
proc summary data=have nway;
class hospid year;
var var1 var2 var3 var4 var5 var6;
id charactervariablename;
output out=test mean=prop1-prop6;
run;
You could use
proc means data=have mean nway;
class hospid year;
var var1 var2 var3 var4 var5 var6;
output out=test mean=/autoname;
run;
Is this data set used for further analysis, such as input to a model or to show a report summary for people to read?
If it is a report then perhaps either Proc Report or Tabulate would be in order.
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.