Hi,
I'm attempting to do what I thought was something simple, i.e. calculated the mean and weighted mean of a variable in Proc Report by using an alias.
I'm running up against an unexpected issue whereby both columns are showing the same numbers, with the calculation apparently being based on the order in which the columns appear (I've renamed the variable weight in the data set to mass for clarity's sake):
/* Both columns calculated unweighted */
proc report data=sashelp.class(rename=weight=mass);
columns sex n height height=height_weighted;
define sex/group;
define height/'Height' mean;
define height_weighted/'Height (weighted)' mean weight=mass;
run;
/* Both columns calculated weighted */
proc report data=sashelp.class(rename=weight=mass);
columns sex n height=height_weighted height;
define sex/group;
define height/'Height' mean;
define height_weighted/'Height (weighted)' mean weight=mass;
run;
The only way I've found to get the right result is to create a copy of the variable in a data step and use that.
/* Create a copy of the variable */
data sashelp_class;
set sashelp.class;
height_weighted=height;
run;
/* Both columns calculated correctly */
proc report data=sashelp_class(rename=weight=mass);
columns sex n height height_weighted;
define sex/group;
define height/'Height' mean;
define height_weighted/'Height (weighted)' mean weight=mass;
run;
Is there another (hopefully less inelegant) way to get the result I'm looking for?
Thanks,
Simon.
Hi:
If you look in the doc, it explains that WEIGHT= cannot be applied to an alias. So that is probably why your alias method did not work.
cynthia
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.