BookmarkSubscribeRSS Feed
jgreenberg321
Fluorite | Level 6

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!

 

 

7 REPLIES 7
PaigeMiller
Diamond | Level 26
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.

--
Paige Miller
jgreenberg321
Fluorite | Level 6

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!

jgreenberg321
Fluorite | Level 6
Quick follow-up question: I also have a character variable for state in the dataset. Is there an efficient way in the same data step to keep that variable in the output ("test") dataset? If not, I can always merge it back in as a separate step; that just seemed less efficient. Thank you again!
PaigeMiller
Diamond | Level 26
proc summary data=have nway;
class hospid year;
var var1 var2 var3 var4 var5 var6;
id charactervariablename;
output out=test mean=prop1-prop6;
run;
--
Paige Miller
jgreenberg321
Fluorite | Level 6
That’s perfect! Thank you!
novinosrin
Tourmaline | Level 20

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;
ballardw
Super User

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.

hackathon24-white-horiz.png

The 2025 SAS Hackathon has begun!

It's finally time to hack! Remember to visit the SAS Hacker's Hub regularly for news and updates.

Latest Updates

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 7 replies
  • 1708 views
  • 0 likes
  • 4 in conversation