The SAS Output Delivery System and reporting techniques

Proc Report - Mean AND Weighted Mean using alias

Reply
N/A
Posts: 1

Proc Report - Mean AND Weighted Mean using alias

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.

SAS Super FREQ
Posts: 8,743

Re: Proc Report - Mean AND Weighted Mean using alias

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

Base SAS(R) 9.4 Procedures Guide, Third Edition

Ask a Question
Discussion stats
  • 1 reply
  • 389 views
  • 0 likes
  • 2 in conversation